0

I did an express install for MS SQL Server 2008 and created a database with a test table. I am running Windows Server 2008 and have IIS, PHP and MS SQL installed. I chose to go with SQL server authentication, where you would need credentials to modify or view the database. I try to print out a simple test table on a web page, but it keeps failing and only returns a white screen..

<?php

$server = "WS1\SQLEXPRESS";
$username = "sa";
$password = "password";
$db = "testdb1";

$dbhandle = mssql_connect($server, $username, $password)
or die ("Cannot connect to SQL Server on $server");

$selected = mssql_select_db($db, $dbhandle)
or die ("Could not open database $db")

echo "You are connected to the " . $db . "database on the " . $server . ".";

$query = "SELECT * FROM table1";

$result = mssql_query($query);

$numRows = mssql_num_rows($result);

echo "<h1>" . $numRows . " Row" . ($numRows == 1 ? "" : "s") . " Returned </h1>";
echo "<li>" . $row[""] . $row[""] . "</li>";

while ($row = mssql_fetch_array($result)) {
  print_r($row);
}

mssql_close($dbhandle);

?>
1
  • Check your error log, see if you are getting an error. Commented Jul 15, 2014 at 18:57

1 Answer 1

2

Ah, the horrific white screen. Sometimes very hard to troubleshoot. Often times it's a simple missing semicolon ...

like the one here:

$selected = mssql_select_db($db, $dbhandle)
or die ("Could not open database $db")

Put a semicolon on the end of that statement and you are back in business.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for catching that small mistake.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.