recursive_acronym
recursive_acronym

Reputation: 3031

Connect PHP on Windows to MS SQL Server

I'm trying to connect Apache/PHP on Windows to SQL Server on the same Windows box.

I am able to connect to the database from my linux virtual machine and I can connect to SQL Server with sqlcmd from the Windows command line. I just can't seem to get PHP to connect, so I assume I'm using an incorrect module somewhere. I've done lots of reading and nothing seems to make this work.

Any ideas?

Apache 2.2, PHP 5.2

$myServer = ".\SQLEXPRESS";
$myUser = "sa";
$myPass = "test1234";
$myDB = "eel";

mssql_connect($myServer, $myUser, $myPass)

Warning: mssql_connect() [function.mssql-connect]: Unable to connect to server: .\SQLEXPRESS in

Upvotes: 0

Views: 4456

Answers (1)

Seth
Seth

Reputation: 131

Seriously. Don't use the MSSQL driver. Use the SQLSRV driver put out by Microsoft. I've used both for long periods of time, and the php_mssql driver really should be deprecated.

Make sure you use the most recent version of the SQLSRV driver for PHP. You can find the most recent stable release (v2.0.1) here: http://www.microsoft.com/download/en/details.aspx?id=20098

That said, there is also a pre-release of the v3 beta.

Make sure you pick the right driver for your version of PHP. Most likely, you need the vc 9. If your using fast-cgi, you'll need the non-thread safe version. Drop it in you php extensions directory and then add it to your php.ini file.

Then, it's essential that you install the SQL Native Client. If you don't have that installed, the driver is dead in the water. You can find it head (search down the page for the actual package): http://www.microsoft.com/download/en/details.aspx?id=3522

Once you've done all that, you should be golden. Make sure you read the included help file for the proper usage.

Upvotes: 1

Related Questions