Connecting to MSSQL 2008 Server Using PHP

We are using MSSQL 2008 server on Win Server 2008 R2 and install separately Apache (2.2.19)

and PHP (5.2.17)

. We installed the MSSQL PHP module and used the following connection string:

$myc = mssql_connect(Server, SiteDatabaseUsername, SiteDatabasePassword) or die('Can\'t connect to mssql Database Server: '.mssql_get_last_message($myc));
$db = mssql_select_db(SiteDatabaseName, $myc) or die('Can\'t find database: '.mssql_get_last_message($myc)); 


But it gives us this error:

Warning: mssql_connect() [function.mssql-connect]: Unable to connect to server: localhost\MSSQLSERVER in D:\Apache2.2\htdocs\adminarea\_core.php on line 89
Can't connect to mssql Database Server:


We have used IP:PORT

, localhost\MSSQLSERVER


, but, it seems, are not going anywhere, can anyone help?


source to share

1 answer

Several things come to mind:

1) Make sure you have the sqlsrv driver package from MS and make sure you load it correctly in php.ini (use phpinfo () to check).

2) If it was a vanilla SQL Server installation, it is likely that only Windows Authentication is enabled. Open SQL Enterprise Manager and make sure SQL Server Authentication is enabled on your database.

3) Make sure you have enabled network access to SQL Server. I didn't immediately understand if the new MS drivers are using named pipes to communicate with the server, or if they expect the server to be accessed over the network.

These are the problems I usually run into when PHP is talking to a new MSSQL server.



All Articles