How to Connect SQL Server 2005 Express using PHP

Posted on 2010-01-12
Medium Priority
Last Modified: 2013-12-12
Recently i was trying to connect to a SQL Server 2005 Express database using PHP on a XP machine and i got the following error :

mssql_connect() [function.mssql-connect]: Unable to connect to server&

Please help me on this very urgent.....
Question by:vineethvp
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2

Accepted Solution

ThiyagarajRamaswamy earned 2000 total points
ID: 26291613
The 8 steps that i followed to resolve this error are as follows :

1.) Downloaded ntwdblib.dll (version : 2000.80.194.0) from Webzila.com

2.) Copied this dll file to apache\bin

3.) Restarted the apache service by going to Control Panel->Administrative Tools->Services.

4.) Went to SQL Server Configuration Manager.

5.) Under SQL Server Network Configuration clicked on Protocols for SQLExpress.

6.) On the right hand side,right clicked on Named Pipes and clicked on Enable

7.) Also, right clicked on TCP/IP and clicked on enable

8.) Restarted the SQL Server Express service. You can do that from the control panel or by issuing the following two commands at the command line :

net stop mssql$sqlexpress

net start mssql$sqlexpress

That was it ! . I was now able to connect to SQL Server 2005 Express  .

In case it still doesnt work for you try the following :

1) Copy php_mssql.dll to apache\ext.

2) Make sure that in your php.ini file , extension=php_mssql.dll is uncommented.

3) Make sure you are using the right port number in your code. You can find out what port SQL Server is listening on by doing the following :

3.1) Go to SQl Server Configuration Manager.

3.2) Under SQL Server Network Configuration click on Protocols for SQLExpress.

3.3) On the right hand side window, right click on TCP/IP , click on Properties.

3.4) In the new window click on the IP Addresses tab

3.5) The value of TCP Dynamic ports is the port number that SQL Server is listening on.

I spent a hell lot of time figuring all this out, and i hope that this post saves you all that trouble.

Author Closing Comment

ID: 31676005
Thanks for your help.
LVL 14

Expert Comment

ID: 26291630
Please use the connection string as below

Data Source=.\SQLExpress;Integrated Security=true; AttachDbFilename=|DataDirectory|\mydb.mdf;User Instance=true;

if it is different please provide urs to troubleshoot the issue more...


LVL 14

Expert Comment

ID: 26291639

WE can connect to MSSQL database by using PHP. To connect to MsSQL we have to enable the MsSQL extension support inside php.ini file. For this we have to uncomment the line saying


The status of the MSSQL support can be checked by using phpinfo function.

Once the support is available we can use different functions to handle data from MSSQL database. Now let us try for connecting to MSSQL database server.

Here are the connection steps. Note that we have used one remote db server but same string will work for a local server also.
$link = mssql_connect ($servername,$dbusername,$dbpassword);

Featured Post

WordPress Tutorial 4: Recommended Plugins

Now that you have WordPress installed, understand the interface, and know how to install new parts, let’s take a look at our recommended plugins.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you start your Windows 10 PC and got an "Operating system not found" error or just saw  "Auto repair for startup" or a blinking cursor with black screen. A loop for Auto repair will start but fix nothing.  You will be panic as there are no back…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question