Installing PHP on IIS and connecting to MSSQL

This was a tough one to get through. I had a PHP page utilizing a MSSQL connection that was hosted on previously on Apache that I needed to move to an IIS6 host. Since I am not very versed in PHP or its configuration, I searched many resources online to properly get this page to run properly on IIS.

With IIS6 already running on Windows 2003 R2
*******************************************************
Tools used:
IIS-Aid_PHP_Installer_x86_529.exe
Update version of ntwdblib.dll
*******************************************************
This app came recommended on the PHP forum. It may have been the easy way out, but it got the job done without having to figure out the CGI configurations which seemed like somewhat of a beast to overcome.

After installing IIS-Aid using the ISAPI option
• update my website properties in IIS to point to the new directory in INETPUB,
• added index.php to the documents list,
• added the PHP extension to ISAPI filters using the php5isapi.dll executable in the IIS-admin/PHP folder
• modify the execute permissions in the home directory tab to scripts and executables
• added the updated version of ntwdblib.dll to the windows/system32 directory (note: I have made it a habit to rename the file extension to .old before replacing, because you never know.)
• uncomment extension=php_mssql.dll in the php.ini located in C:\IIS-Aid\PHP
• uncomment extension=php_pdo_mssql.dll in the php.ini located in C:\IIS-Aid\PHP
• replaced the old version of ntwdblib.dll in the C:\IIS-Aid\PHP directory
The last step is very important to enable to MSSQL connection to work properly.
Lastly restart the IISADMIN service. I think that covers it.
Just in case you need the PHP code to connect to MSSQL this is the code used.
*******************************************************
// Connect to MSSQL
$link = mssql_connect( ‘hostname or IP’, ‘username’, ‘password’ ) or die(“Error: Could not connect to database”);
mssql_select_db( ‘databasename’ ) or die(“Error: Could not select database”);
*******************************************************

Hope this helps!
If you want to test your connection you can also use this PHP code. Simply create a file with a text editor called test.php
And paste this in there to test.
*******************************************************
<?php
echo mssql_connect(“hostname or IP”,”username”,”password”);
?>
*******************************************************
Or you can use this:
*******************************************************
<?php
if (function_exists(‘mssql_fetch_row’)) {
echo “MSSQL functions are available.<br />\n”;
} else {
echo “MSSQL functions are not available.<br />\n”;
}
?>
*******************************************************

Good luck!

About steve