Connect php adodb MSSQL

I have a linux server that I am trying to use php adodb to connect to an MSSQL server.

include('adodb5/adodb.inc.php'); $conn =& ADONewConnection('odbc_mssql'); $dsn = "Driver={SQL Server};Server=MSSERVER;Database=Northwind;"; $conn->Connect($dsn,'sa','password')or die("Unable to connect to server"); 

I installed mssql via yum, etc., and I know that the server can connect to it, since I tried the following:

 $db = @mssql_connect("MSSERVER","sa","password") or die("Unable to connect to server"); mssql_select_db("Northwind"); // Do a simple query, select the version of // MSSQL and print it. $version = mssql_query('SELECT @@VERSION'); $row = mssql_fetch_array($version); echo $row[0]; // Clean up mssql_free_result($version); 

Any ideas why my adodb is not connecting, or any examples of how I can connect, would be much appreciated.

+2
source share
2 answers

I solved this by looking at this forum: http://ourdatasolution.com/support/discussions.html?topic=4200.0

The correct code is:

 <?php include("adodb5/adodb.inc.php"); //create an instance of the ADO connection object $conn =&ADONewConnection ('mssql'); //define connection string, specify database driver $conn->Connect('xxx.xxx.x.xxx:1400', 'user', 'password', 'DbName'); //declare the SQL statement that will query the database $query = "select * from table"; $rs = $conn->execute($query); //execute the SQL statement and return records $arr = $rs->GetArray(); print_r($arr); ?> 

Hope this helps someone else.

+5
source

With php 5.3 above, the php_mssql module php_mssql no longer supported for windows.

The solution is to download the MicroSoft PHP driver from http://www.microsoft.com/en-us/download/details.aspx?id=20098 .

This installer will extract the modul dll files into the php extension directory.

Include the correct version in php ini (e.g. for php 5.3 ThreadSafe):

 extension=php_sqlsrv_53_ts.dll 

After that, you can use adboDb again, but you should use mssqlnative as adodbtype. And the connection with ip and port did not work for me, but ipaddress\\SERVERNAME worked (see. Sample code)

 <?php include("adodb5/adodb.inc.php"); //create an instance of the ADO connection object $conn =&ADONewConnection ('mssqlnative'); //define connection string, specify database driver // $conn->Connect('xxx.xxx.x.xxx:1400', 'user', 'password', 'DbName'); $conn->Connect('xxx.xxx.x.xxx\\SERVERNAME', 'user', 'password', 'DbName'); //declare the SQL statement that will query the database $query = "select * from table"; $rs = $conn->execute($query); //execute the SQL statement and return records $arr = $rs->GetArray(); print_r($arr); ?> 
+1
source

All Articles