PHP with MSSQL not working

Sometimes you might wonder why you are not able to connect from PHP script with your MSSQL database as you have enabled php_mssql.dll extension from your php.ini.

Below are the step to resolve this issue;

But before we given the solution, you might get the following error message, however the error might just unable to connect to the MSSQL database without any further detail.

Assume you were using IIS6/7 with PHP 5.2.x(Microsoft Windows Server 2003/2008),  you might get such issue if you are install the PHP with source installation.


Warning: mssql_connect() [function.mssql-connect]: Unable to connect to server: localhost:1433 in C:\Domains\wwwroot\php_mssql.php on line 5
Couldn’t connect to SQL Server on localhost:1433

1. Download file ntwdblib.dll from URL of
2. Go to the server hosted for your PHP script.
3. Go to PHP directory, assume you are using C:\Program Files\PHP5.2.x\, backup original ntwdblib.dll.
4. Replace the file as downloaded from Step 1.

Test again, and your problem should resolved.

You may refer to the URL as below for more information on the PHP_MSSQL connect page available from PHP.Net

Published by

Mick Genie

Mick Genie is the founder of and working at ExaBytes Network Sdn Bhd and WPWebHost web host company. He is expertise in Windows and Linux environment especially web hosting related information, tips and trick as well as the IT Information.

2 thoughts on “PHP with MSSQL not working”

  1. I followed the same steps , but it was not working,
    Warning: mssql_connect() [function.mssql-connect]: Unable to connect to server: localhost in D:\xampp\htdocs\php\test\index.php on line 4
    Database Connect Failed.
    Warning: mssql_close() expects parameter 1 to be resource, boolean given in D:\xampp\htdocs\php\test\index.php on line 14

Comments are closed.