在我确信还有很多其他问题中,$result 变量没有被识别
得到一个
致命错误:在非对象上调用成员函数 fetch_assoc()
我不知道为什么。任何帮助,将不胜感激。这是代码:
<html>
<body>
<?PHP
$db = new mysqli('localhost', 'root', '', 'edumacation');
if($db->connect_errno > 0){
die('Unable to connect to database [' . $db->connect_error . ']');
}
$result = <<<SQL
SELECT *
FROM `student`
WHERE `id` = 1
SQL;
while($row =
$result->fetch_assoc()){
echo "<table border='1'><tr><th>Name</th><th>Grade</th><th>Favorite Teacher</th><th>Date Enrolled</th></tr>";
echo "<tr><td>" . $row['first_name'] . "</td><td>" . $row['grade'] . "</td><td>" . $row['fav_teacher'] . "</td></tr>" . $row['enrolled'] . "<br />";
echo "</table>";
}
?>
</body>
</html>