I've recently installed PHP4 on an IIS6/Win2K3 environment and that is working well. I can run any php script and it will output with no problem except for the ones that require to connect to MS SQL. The following is how I configured for MS SQL:

  • php.ini settings are as follows...
    extension_dir = "C:\php4\extensions"
    extension = php_mssql.dll

  • added "C:\php4" and "C:\php4\extensions" to windows environment settings

  • moved "ntwdblib.dll" to "C:\Windows\system32"

  • created ODBC sources

I've created an index.php to test the connection with the following content:

<?
if (mssql_connect(<dsn>, <username>, <password>))
   echo "connected to db...";
else
   echo "unable to connect to db: " . mssql_get_last_message();
?>

So far when I go to that page, the code seems to hang on the mssql_connect() line.

We have another PHP server running on Apache/Linux and it can connect without any problem using FreeTDS. And I've tested connecting to the db via other ways (i.e. testing ODBC, using excel, telnet to port 1433 of db) and they've all been successful. So I have to think that it's the PHP configuration issue or that I forgot to install something necessary.

Anyone have any idea what I should be looking for? I've been trying to solve this for a while now and it's starting to drive me crazy. I'd prefer we stick with the Linux/Apache setup (if it ain't broke why fix it) but the powers that be wanted me to test and evaluate the possibility of moving to IIS/Win setup.

Thanks in advance for any help you can provide.

    I've turned on the error loggings and here's what PHP is returning...


    Warning: mssql_connect(): Unable to connect: SQL Server is unavailable or does not exist. Specified SQL server not found. (severity 9) in C:\Inetpub\wwwroot\index.php on line 2

    Warning: mssql_connect(): Unable to connect to server: dbname in C:\Inetpub\wwwroot\index.php on line 2

    Fatal error: Maximum execution time of 30 seconds exceeded in C:\Inetpub\wwwroot\index.php on line 3

    Just out of curiousity, I replaced the dsn in the connect call to the domain of the db like so:

    mssql_connect('dbserver.domain.com', 'username', 'password');

    and I received the following message instead:


    Warning: mssql_connect(): Db-library network communciations layer not loaded. (severity 9) in C:\Inetpub\wwwroot\index.php on line 2

    Warning: mssql_connect(): Unable to connect to server: dbserver.domain.com in C:\Inetpub\wwwroot\index.php on line 2

    Disclaimer: "dbname" and "dbserver.domain.com" are replacement to the actual dsn and domain of the database.

    Any ideas?

      Consider this one resolved. Our server was missing the SQL Client Network Utility so "ntwdblib.dll" wasn't being loaded.

      Excuse me while I use my baseball bat to talk to the admin guy...hehe.

        mssql_connect() establishes a connection to a MS SQL server. The servername argument has to be a valid servername that is defined in the 'interfaces' file.

        Is that set up correctly?

        Otherwise; get MySQL :p

        EDIT: Woops, posted reply before I read your post. Be nice to us tech guys plz 🙁

          Write a Reply...