我正在尝试使用预准备语句获取数据库,但是我得到了“对非对象调用成员函数fetch_assoc()”错误 .
我究竟做错了什么?
谢谢你的帮助!!
$peopleID = $_GET['peopleID'];
$stmt = $link->prepare("SELECT * FROM people WHERE peopleID = ?");
$stmt->bind_param('i', $peopleID);
$result = $stmt->execute();
$stmt->store_result();
if ($stmt->num_rows >= "1") {
while($row = $result->fetch_assoc()) {
$firstname = $row ['firstname'];
$lastname = $row ['lastname'];
}
}
1 回答
mysqli_stmt::execute()返回bool(true / false),而不是mysqli_result .
从php 5.3开始,您可以使用mysqli_stmt::get_result从语句实例中获取mysqli_result .