Can't connect to MS SQL 2005 with PHP

I’m having huge problems trying to get a PHP/MS SQL connection working on Windows 7. Here is what I have done.

  1. Installed xampp.

I’ve been using xampp to develop PHP/MySQL applications for some time with great success.

  1. Installed SQL Server 2005 Express. There were quite a number of permissions issues here on Win 7 and I had to run the installer as admin.

  2. Checked the properties of the protocols and enabled TCP/IP and ip addresses.

  3. Set up a test PHP test script as follows


<?php

$server = 'Andy-PC\\SQLEXPRESS';

// Connect to MSSQL
$link = mssql_connect($server, 'sa', 'mypasswordhere');

if (!$link) {
    die('Something went wrong while connecting to MSSQL');
}
?>

No Joy, anybody any ideas?

Use microsoft sql extensions sqlsrv http://sqlsrvphp.codeplex.com/ it working for me under sql server 2008

Make it:


if (!$link) {
    die('Something went wrong while connecting to MSSQL, because: '. mssql_get_last_message());
}

The second post down has:

By far the easiest way that I’ve found to connect to a SQL server is to route it through a ODBC connection.

  1. Administrative Tools -> Data Sources (ODBC)
  2. System DNS
  3. Add… “SQL Server”

Then just use odbc_connect(“sql_test”, “user”, “pass”) instead.

did you try this

Thanks, I’ve been through that list twice now and tried many if not all of the suggestions. The trouble is there are so many new concepts to me here I am likely getting close then undoing some of the problems I’ve already solved.

I tried setting up a new user and giving all permissions and can confirm I can use that user account to connect using server management studio and sql server authentication mode.

I’ve also checked the TCP/IP settings and port and made sure I was connecting with 1433. I’d be willing to set up an RDP connection for anybody that knows how I can get this sorted.

This might help:

http://php.net/manual/en/function.mssql-connect.php

“localhost\SQLEXPRESS” and “localhost” don’t work either. More helpful error messages would be useful :slight_smile:

Shot in the dark. Have you tried “localhost” for ‘$server’. I had this problem with ASP.NET and SQL Server, and it worked for me.

Just a follow up to say I have checked to make sure the ms sql php extension is loaded with phpinfo() and it is.