MS SQL Problem
| From: | Christopher J. Crane | Date: | Thu, 12 Sep 2002 20:31:20 +0000 |
| Subject: | MS SQL Problem | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-116200@lists.php.net to get a copy of this message | ||
I am trying to get a script to work to retrieve data from a MS SQL database.
I also tried using a ODBC connection, but that didn't work either.
Here is the error I get;
Warning: MS SQL: Unable to connect to server: LocalServer in
C:\WEBS\CTTechCouncil\stocks\mssql.php on line 7
DATABASE FAILED TO RESPOND.
Here is what I have:
<?PHP
$hostname = "LocalServer";
$username = "ctorg";
$password = "sbc123";
$dbName = "DirectoryDB";
MSSQL_CONNECT($hostname, $username, $password) or DIE("DATABASE FAILED TO
RESPOND.");
mssql_select_db($dbName) or DIE("Table unavailable");
$query = "SELECT * FROM Company";
$result = MSSQL_QUERY($query);
$number = MSSQL_NUM_ROWS($result);
$i=0;
if ($number == 0) :
print "No data?";
elseif ($number > 0) :
print "Data:\n";
while ($i < $number) :
$name = mssql_result($result,$i,"CompanyName");
print $name;
print "
";
$i++;
endwhile;
endif;
?>