I have read from different forums, PHP website and Microsoft website how to connect PHP to MS SQL Server but the provided solutions didn't worked for me. If you could help me in this would be greatly appreciated.

Edited by Jerome_3: Further details

3 Years
Discussion Span
Last Post by Jerome_3

The first issue on connecting to a MSSQL database probably pertains to whether you are using and express version or not. The other problem will relate to which PHP drivers you have decided to use, there is a native Microsoft driver and the default PHP driver. I have discovered that it isquite a mission to get the PHP configuration correct.

Below a code snippet for native drivers.

$connectionInfo["UID"] = $username;
$connectionInfo["PWD"] = $password;
$connectionInfo["Database"] = "TESTDB";

$this->dbh = @sqlsrv_connect(  "\SQLEXPRESS", $connectionInfo );

And you can download the drivers here

Click Here

Edited by andrevanzuydam: Code was a bit wrong :(


Where is your code, and what error you get while running your script?

In addition to this (you still haven't answered), what exactly is your setup?


I run a WAMP in my PC(host-Win 7) and run the SQL Server in a virtual machine(Win Server 2003).


Did you set SQL Server to accept remote connections? Since the VM is a different machine PHP can't connect to localhost.


Thanks for replies guys, I was able to figure out the problem. I was using SQL Authentication in my PHP code but db server is using Windows Authentication. To correct the problem, I change server authentication then run the code again and this time it worked.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.