PHP + MS SQL Server – SUCCESS!
Thanks to all!
PHP is on an IIS server, SQL Server is on a different server in the same domain.
Changes made to PHP
o Add MS SQL Server Client Tools
o Uncomment the extension=php_mssql.dll statement in the php.ini file
o Add system variable PHPRC value c:\php
o Use ntwdblib.dll version 2000.80.194.0 (ver 2000.2.8.0 did not work); copied the files to c:\windows\system32 directory on the PHP server
Changes made to IIS
o Set up IUSER_machinename account with password
Changes made to MS SQL Server
o Create IUSER_machinename account with password – synchronize with IIS password
o Add IUSER as login
o Add IUSER as user on database, including permissions
After all of these steps were followed, the following PHP script ran correctly:
<html><head><title>MsSQL Table Viewer</title></head><body>
<?php
$db_host = hostname';
$db_user = 'username';
$db_pwd = 'password';
$database = 'dbname';
$table = 'tablename';
if (!mssql_connect($db_host, $db_user, $db_pwd))
die("Can't connect to database");
if (!mssql_select_db($database))
die("Can't select database");
// sending query
$result = mssql_query("SELECT * FROM {$table}");
if (!$result) {
die("Query to show fields from table failed");
}
$fields_num = mssql_num_fields($result);
echo "<h1>Table: {$table}</h1>";
echo "<table border='1'><tr>";
// printing table headersfor($i=0; $i<$fields_num; $i++)
{
$field = mssql_fetch_field($result);
echo "<td>{$field->name}</td>";
}
echo "</tr>\n";
// printing table rows
while($row = mssql_fetch_row($result))
{
echo "<tr>";
// $row is array... foreach( .. ) puts every element
// of $row to $cell variable
foreach($row as $cell)
echo "<td>$cell</td>";
echo "</tr>\n";
}
mssql_free_result($result);
?>
</body></html>[/COLOR]