Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

How to Connect SQL Server 2005 Express using PHP

Posted on 2010-01-12
4
Medium Priority
?
400 Views
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.....
0
Comment
Question by:vineethvp
  • 2
4 Comments
 
LVL 4

Accepted Solution

by:
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.
0
 
LVL 5

Author Closing Comment

by:vineethvp
ID: 31676005
Thanks for your help.
0
 
LVL 14

Expert Comment

by:Kalpan
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...

thanks

Kalpan
0
 
LVL 14

Expert Comment

by:Kalpan
ID: 26291639
@vineethvp

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

extension=php_mssql.dll


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.
$dbusername='username';
$dbpassword='password';
$servername='servername';
$link = mssql_connect ($servername,$dbusername,$dbpassword);
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article discusses four methods for overlaying images in a container on a web page
This holiday season, we’re giving away the gift of knowledge—tech knowledge, that is. Keep reading to see what hacks, tips, and trends we have wrapped and waiting for you under the tree.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

580 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