Link to home
Start Free TrialLog in
Avatar of vineethvp
vineethvpFlag for India

asked on

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.....
ASKER CERTIFIED SOLUTION
Avatar of ThiyagarajRamaswamy
ThiyagarajRamaswamy

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of vineethvp

ASKER

Thanks for your help.
Avatar of Kalpan
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
@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);