PHP Unable to Connect to MSSQL

March 12th, 2009 | Tags: ,

Update: This article is considered outdated, and is only valid for PHP versions before 5.3. I’ve started an IIS Tutorial Series on Talking to SQL Server with PHP on IIS, which is valid for any versions of PHP 5.2.4 and later.

I have been pulling my hair trying for many hours to connect to a MSSQL server remotely with PHP.  I was able to connect using ODBC but I wanted a more elegant and native solution.  Trying to connect using PHP’s MSSQL database library constantly gave me the error:

Warning: mssql_connect() [function.mssql-connect]: Unable to connect to server: 172.xxx.xxx.xxx

I’ve tried using the computer name and several other solutions.  Upon doing a lot of research and reading the user notes on the PHP website, and trying out several solutions before finding out a working solution.  I’ve found that the file ntwdblib.dll packaged with PHP5 (currently 5.2.9-1) is an old version (2000.2.8.0).  Most people suggested replacing it with the later version, 2000.80.194.0.

Click here to download this version of the file: ntwdblib.dll

I’ve replaced the file and restarted my IIS webserver and the connection was successful!  I hope this helps for those searching for the solution.

  1. Vandalis
    May 11th, 2009 at 07:47
    Reply | Quote | #1

    You just saved my brain from meltin away… thank you so much!!!

  2. May 12th, 2009 at 00:25
    Reply | Quote | #2

    No problem! Glad that it helped someone out!