We have a database running on Windows Server 2008 R2, SQL Server 2008 R2. I need to query the database via PHP (I'm also open to other options) and display the data in a web page.
I have tested connectivity with my username, password and server name using a UDL test file. My connection is successful.
My web server has PHP 5.4 installed and working.
I have built a PHP script that is supposed to connect and query the database but I get a server error.
<?php
$myServer = "ipaddress";
$myUser = "username";
$myPass = "password";
$myDB = "dbname";
//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 fullName, email_address, pos_desc";
$query .= " FROM dbo.EMPLOYEE_VIEW ";
$query .= "WHERE grp_cde='STAFF'";
//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);
?>
Keep in mind the Database server and the Web Server are both running Windows Server 2008 R2 and exist in the same domain.
The only error I receive is: 500 - Internal server error. There is a problem with the resource you are looking for, and it cannot be displayed.
Is there anything I can do to troubleshoot why this is not working?
I appreciate any and all help on this question.