Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

mssql_connect() from IIS box

Status
Not open for further replies.

prplrhead

Programmer
Feb 26, 2007
8
US
My php is not able to connect to a SQL Server box. PHP is *NOT* running as CGI but rather ISAPI filter. Here is my example code:

<html>
<head>
<?php
$conn = mssql_connect("Server","User","Password");
if($conn){
if(!mssql_select_db("Database",$conn)){
die("Database unavailable");
}
$query = "SELECT * FROM User.Table";
$result = mssql_query($query);
if(!$result){
die("SQL error");
}
while($row = mssql_fetch_row($result)){
echo $row["column"] . "<br/>";
}
}
else die("Server unavailable");
?>
</head>
<body>
<center>
<table>
<tr><td>Data</td></tr>
<?php echo $tablerow; ?>
</table>
</center>
</body>
</html>

The resulting output is:

<html>
<head>

... and that's it. No error, nothing. It just dies w/o any of the messages declared in my code. That's why I put the PHP code in the head because when I ran prior to the <html> declaration I got only the standard html element tags. This way I know it delivers *part* of the document.

My configuration is:
PHP Version 5.2.1
Windows 2003
IIS 6
MS SQL 2000
PHP Installed to: C:\Program Files\PHP\
PHP.INI File in: C:\Program Files\PHP\php.ini
Extension in PHP.INI: extension=php_mssql.dll
mssql.ddl in C:\Program Files\PHP\ext AND C:\Windows\System32
ntwdblib.dll in C:\Windows\System32
SQL Server client tools installed on IIS box
The IIS and SQL Server boxes are separate, but other apps (both ASP and Perl) are connecting to that server and DB using the same credentials specified in mssql_connect().

I've run out of things to try. Somebody please help!!
 
is mssql set up to accept tcp connections rather than named pipes?
 
i've reorganised your code a tiny bit in an attempt to get some earlier warning signs.

Code:
<html>
<head>
<?php
    $conn = mssql_connect("Server","User","Password") or die('Server unavailable');
    mssql_select_db("Database",$conn) or die ("Database unavailable");
	$query = "SELECT * FROM User.Table";
	$result = mssql_query($query) or die ('SQL Error');

	while($row = mssql_fetch_row($result)){
		echo '<pre>';
		print_r($row);
		echo '<hr/></pre>';
	}
?>
</head>
<body>
<center>
    <table>
        <tr><td>Data</td></tr>
        <?php echo $tablerow; ?>
    </table>
</center>
</body>
</html>

can you also make sure that error_reporting is set to E_ALL and that display_errors is turned on in your php.ini (restart IIS after making changes).
 
that would mean that you have not enabled the mssql extension properly in php.ini (or for whatever other reason it is not loading). make sure that the path to the extensions is properly set in php.ini and that the php.ini you are changing is actually the right php.ini (can be derived from a call to phpinfo()).
 
From phpinfo():
C:\Program Files\PHP\php.ini

From C:\Program Files\PHP\php.ini line 633:
Code:
extension=php_mssql.dll
 
does phpinfo also tell you that the dll has been loaded? nb the extension path.
 
I didn't know there was a way to see that in phpinfo(). Here is a link to the relevant phpinfo page:

Perhaps this will expedite your kind efforts. This is just a framed page from my site to keep my client's domain out of the archives.

I guess I'm assuming that the extension is not loading in any event. I just have no idea why. I also have loaded the curl extension in the php.ini, but have not done any testing on it - not even sure how at this point (I am primarily an ASP guy) but if you know a quick call to a curl function that I could test that might also be revealing.

Thanks for all you have provided so far.
 
yup, that shows that the extension is not loaded.

is the extensions in the directory
Code:
C:\Program Files\PHP\ext

also turn display_startup_errors on in php.ini and also set a path to the error log. restart the server and have a look in the php logs to determine whether there is anything there of interest.

on curl the php manual has the following sample code to try
Code:
<?php
// create a new cURL resource
$ch = curl_init();

// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, "[URL unfurl="true"]http://www.example.com/");[/URL]
curl_setopt($ch, CURLOPT_HEADER, 0);

// grab URL and pass it to the browser
curl_exec($ch);

// close cURL resource, and free up system resources
curl_close($ch);
?>

it appears from your phpinfo snapshot that the curl library is properly installed on your system
 
PHP Startup: Unable to load dynamic library 'C:\Program Files\PHP\ext\php_mssql.dll' - The specified module could not be found.

Here's the thing, I've checked & double checked - that DLL is in that directory. I'm at a loss.
 
hmmm... try the old trick of putting a copy in the php directory and in the system32 directory.

restart the server.

sorry - this is a kludge and a half - i'm sure there is a more genteel way of doing this: i just don't know it!
 
Should have mentioned that I already have a copy in the system32 dirictory.
 
are you 100% certain that both files are identical? could it be that one of the files is for an older version of php?
 
And there it is! I was 100% certain they were identical because I copied from one directory to another. When I went to look at the file properties for version info, however, there was none. The date on that dll was different from the other extension dll's, however - two years earlier!

So I downloaded the entire zip of the current PHP install (I used an .msi to install) and striped the dll out of there. Voila! I guess the MSI installer did not overwrite the old dll. That's the only explanation I have at least.

Thank you for the help. I don't know how long it would have been before I came up with that on my own.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top