Php 错误:调用未定义的方法mysqli_stmt::fetch_object()

Php 错误:调用未定义的方法mysqli_stmt::fetch_object(),php,Php,我正在尝试让这个select语句工作,但是当我运行页面时,返回了以下错误:调用未定义的方法mysqli\u stmt::fetch\u object() 我的声明如下: <?php $id = escape($_GET['id']); $records = array(); $results = $db->prepare("SELECT * FROM `bookings` WHERE id = ?"); $results->bind_param('i', $id); if

我正在尝试让这个select语句工作,但是当我运行页面时,返回了以下错误:
调用未定义的方法mysqli\u stmt::fetch\u object()

我的声明如下:

<?php 
$id = escape($_GET['id']);
$records = array();
$results = $db->prepare("SELECT * FROM `bookings` WHERE id = ?");
$results->bind_param('i', $id);
 if ($results->execute()) {
while ($row = $results->fetch_object()) {
    $records[] = $row;
}
$results->free();
}
?>

然后我想像这样循环如下:

<?php foreach ($records as $data) {... ?>


我做错了什么?

使用准备好的语句没有
获取数组()。改用mysqli\u stmt::fetch()
。检查手册:


从中获取答案

如果要获取对象,请使用PDO。mysqli不支持它