我正在尝试使用 PHP 从 MS SQL 数据库中访问和读取视图。现在我只是想在屏幕上显示结果。当我测试时,我的页面什么也没有显示。这就是我所拥有的:
<?php
$myServer = "localhost";
$myUser = "username1";
$myPass = "password1";
$myDB = "database1";
//connect to database
$dbhandle = mssql_connect($myServer, $myUser, $myPass)
or die("Couldn't connect to SQL Server on $myServer");
//select database
$selected = mssql_select_db($myDB, $dbhandle)
or die("Couldn't open database $myDB");
//declare statement
$query = "SELECT ProductId";
$query .= "FROM Inventory ";
$query .= "WHERE UPC='15813658428' and ManufacturerID=465";
//execute the query
$result = mssql_query($query);
$numRows = mssql_num_rows($result);
echo "<h1>" . $numRows . " Row" . ($numRows == 1 ? "" : "s") . " Returned </h1>";
//display results
while($row = mssql_fetch_array($result))
{
echo "<li>" . $row["id"] . $row["name"] . $row["year"] . "</li>";
}
//close
mssql_close($dbhandle);
?>