我正在尝试解决这个问题。但是做不到。请帮忙
我正在尝试查看数据库中的所有记录,但得到“致命错误:调用非对象上的成员函数 query() ....”及其指向
if ($result = $mysqli->query("SELECT ProductName, Description, Price, Size FROM Products ORDER BY ProductID"))
这是我的完整代码
<?php
include('db_connect.php');
**$mysqli = new mysqli("localhost", "netelmbn", "password", "netelmbn");
if ($mysqli->connect_errno) {
printf("Connect failed: %s\n", $mysqli->connect_error);
exit();
}**
if ($result = $mysqli->query("SELECT ProductName, Description, Price, Size FROM Products ORDER BY ProductID"))
{
if ($result->num_rows > 0)
{
echo "<table border='1' cellpadding='10'>";
echo "<tr><th>ProductID</th><th>ProductName</th><th>Description</th><th>Price</th><th>Size</th></tr>";
while ($row = $result_fetch_object())
{
echo "<tr>";
echo "<td>" . $row->ProductID . "</td>";
echo "<td>" . $row->ProductName . "</td>";
echo "<td>" . $row->Description . "</td>";
echo "<td>" . $row->Price . "</td>";
echo "<td>" . $row->Size . "</td>";
echo "<td><a href='records.php?ProductID=" . $row->ProductID . "'>Edit</a></td>";
echo "<td><a href='delete.php?ProductID=" . $row->ProductID . "'>Delete</a></td>";
echo "</tr>";
}
echo "</table>";
}
else
{
echo "No results to display!";
}
}
else
{
echo "Error: " . $mysqli->error;
}
$mysqli->close();
?>