500 Error when connecting to MSSQL

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
VarwigDude
Forum Newbie
Posts: 12
Joined: Tue Mar 31, 2009 8:08 pm

500 Error when connecting to MSSQL

Post by VarwigDude »

Hey Everyone!

Have an tring to test php with MSSQL Express on my windows 2008 server. I run the Following Code

Code: Select all

 
<?php
if (function_exists('mssql_connect'))
echo "Okay, mssql_connect is there";
else
echo "Hmmm .. mssql_connect is not even there";
?> 
 
And The Result is "Okay, mssql_connect is there"

But When I Run this

Code: Select all

 
<?php
$myServer = "myservername";
$myUser = "administrator";
$myPass = "mypassword";
$myDB = "mydatabasename"; 
 
//connection to the database
$dbhandle = mssql_connect($myServer, $myUser, $myPass)
  or die("Couldn't connect to SQL Server on $myServer"); 
 
//select a database to work with
$selected = mssql_select_db($myDB, $dbhandle)
  or die("Couldn't open database $myDB"); 
 
//declare the SQL statement that will query the database
$query = "SELECT id, name, year ";
$query .= "FROM cars ";
$query .= "WHERE name='BMW'"; 
 
//execute the SQL query and return records
$result = mssql_query($query);
 
$numRows = mssql_num_rows($result); 
echo "<h1>" . $numRows . " Row" . ($numRows == 1 ? "" : "s") . " Returned </h1>"; 
 
//display the results 
while($row = mssql_fetch_array($result))
{
  echo "<li>" . $row["id"] . $row["name"] . $row["year"] . "</li>";
}
//close the connection
mssql_close($dbhandle);
?> 
 
It comes up with "500 - Internal server error.
There is a problem with the resource you are looking for, and it cannot be displayed."

Anyone know what is going on. phpinfo(); shows up perfectly.

In the PHP.ini i have uncommented the "extension=php_mssql.dll"

Thank You
Post Reply