How to Connect SQL Server 2005 Express using PHP

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.....
LVL 5
vineethvpAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ThiyagarajRamaswamyCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
vineethvpAuthor Commented:
Thanks for your help.
0
KalpanCommented:
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
KalpanCommented:
@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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.