Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm a MySQL/Apache user, trying my hand with IIS and SQL server, so please, if this is a stupid question have patience.

I'm using IIS version 7.5. PHP version 5.3.13 and SQL server 2005 IIS is running on port 90, not sure if that will make a difference or not. I know my sql server is running because I can explore/connect to it in Server management studio.

I know php is configured properly, because //localhost:90/phpinfo.php works fine.

I updated the php_msql.dll extension in phpinfo to: extension=ext/php_msql.dll

EDIT- However, when I run phpinfo() under the "configure command" row, this is present: --without-mssql

I found/downloaded the ntwdblib.dll and placed it in both sys32 and php root.

All these things were supposed to fix the issue, and they haven't.

This is the code I'm using, straight from php.net:

<?php
// Server in the this format: <computer>\<instance name> or 
// <server>,<port> when using a non default port number
$server = 'localhost';

// Connect to MSSQL
$link = mssql_connect($server, 'uname', 'pwd');

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

obviously I'm using a real username and password, but when I load the file in my browser, I receive a 500 error. Upon checking the log, this is what is displayed:

2012-06-25 12:41:29 ::1 GET /test.php - 90 - ::1 Mozilla/5.0+(Windows+NT+6.1;+WOW64)+AppleWebKit/536.5+(KHTML,+like+Gecko)+Chrome/19.0.1084.56+Safari/536.5 500 0 0 5

That (to me) doesn't help me much. What am I doing wrong?

Thank you

share|improve this question
    
Which edition of SQL Server 2005 are you using? Is it Express? –  squillman Jun 25 '12 at 13:21
    
I'm not 100%, under version in programs and features, there is nothing listed. However, underneath that there is "SQL Server 2005 backward compatibility" it's version is 8.05.2312 –  Ryan Jun 25 '12 at 13:25
    
Look at the Services (Start | Run | services.msc | [enter]) and look for the SQL Server service(s) in the Name column. What are the service names you see beginning with SQL Server? –  squillman Jun 25 '12 at 13:34
    
SQL Server(MSSQLSERVER) -> started SQL Server Active directory helpser SQL Swerver Agent (MSSQLSERVER) SQL Server Browser SQL SERVER FullText Search SQL Server VSS WRITER –  Ryan Jun 25 '12 at 13:40
add comment

2 Answers

Try appending the instance name to the servername. Below grabbed from http://php.net/manual/en/function.mssql-connect.php

<?php
// Server in the this format: <computer>\<instance name> or 
// <server>,<port> when using a non default port number
$server = 'KALLESPC\SQLEXPRESS';

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

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

EDIT

Also, verify the following:

  • Make sure you have set up a user with "SQL SERVER authentication" who has rights to connect
  • Also make sure after you install and still have problems to run PHPinfo and check that you find the below:

    • PHPINFO: mssql
    • MSSQL Support enabled
  • Use one of the following methods to specify the server.

    • hostname:port (Linux), or hostname,port (Windows)
    • .\MSSQLINSTANCENAME
    • COMPUTER\MSSQLINSTANCENAME
    • Replace hostname with IP address to rule out resolution issues
  • Use ODBC connector

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

      • Then just use odbc_connect("sql_test", "user", "pass") instead.
share|improve this answer
    
For your setup it probably should be localhost\MSSQLSERVER –  ZnArK Jun 25 '12 at 13:58
    
still no dice, and wouldn't id die instead of displaying a 500 error? –  Ryan Jun 25 '12 at 14:15
    
My understanding is that the 500 message means the script has died. I'm not familiar enough with IIS to tell you where this would log, but I would think that there would be something comparable to /var/log/apache2/error.log. That logfile usually shows something valuable in *nix. –  ZnArK Jun 25 '12 at 16:13
    
Have you tried the following: mssql_connect(".\MSSQLSERVER", $dbUser, $dbPass); ? There are a number of good suggestions on the comments here php.net/manual/en/function.mssql-connect.php –  ZnArK Jun 25 '12 at 16:13
    
Check my edits above, let us know if any of them work. Hope one of them does :) –  ZnArK Jun 25 '12 at 16:28
show 1 more comment
up vote 0 down vote accepted

Alright, so I found the answer, after 2/3 of a day. Apparently as of php 5.3, php no longer uses the msql.dll extension when operating on IIS. Now, it uses something called sqlsrv.dll in its place. Also, with this new extension, comes the need to use the sqlsvr api from php available Here. So in essence, I was using mssql_connect, when I should have been using sqlsrv_connect.

That still doesn't solve my issues with error logging, and I still can't connect to the server, but that is due to a bad username/pwd combo.

So thank you all for your help, hopefully someone finds this useful sometime.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.