简体   繁体   English

PHP无法连接到MS SQL Server 2008 IIS

[英]PHP cannot connect to MS SQL Server 2008 IIS

I did an express install for MS SQL Server 2008 and created a database with a test table. 我为MS SQL Server 2008进行了快速安装,并创建了带有测试表的数据库。 I am running Windows Server 2008 and have IIS, PHP and MS SQL installed. 我正在运行Windows Server 2008,并已安装IIS,PHP和MS SQL。 I chose to go with SQL server authentication, where you would need credentials to modify or view the database. 我选择使用SQL Server身份验证,在此您需要凭据才能修改或查看数据库。 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);

?>

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. 在该语句的末尾放一个分号,您就可以重做。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM