我想通过连接到 SQL Server 来提取数据库中的数据。我可以连接到 SQL Server,但无法打印数据。我得到空白屏幕输出。问题是什么?
<?php
$myServer = "...";
$myUser = "...";
$myPass = "....";
$myDB = "...";
//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 form_adres, form_sehir, form_adsoyad";
$query .= "FROM databasename.omg_user.ie_form";
$query .= "WHERE form_no='15275'";
//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>";
while($row = mssql_fetch_array($result))
{
echo "<li>" . $row["form_adres"] . $row["form_sehir"] . $row["form_adsoyad"] . "</li>";
}
//close the connection
mssql_close($dbhandle);
?>