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

时间:2014-04-23 16:37:05

标签: php

我试图让这个select语句工作但是当我运行页面时,我返回了这个错误:Call to undefined method mysqli_stmt::fetch_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) {... ?>

我做错了什么?

1 个答案:

答案 0 :(得分:1)

使用预准备语句没有fetch_array()。请改用mysqli_stmt::fetch()。查看手册:http://www.php.net/manual/en/mysqli-stmt.fetch.php

https://stackoverflow.com/a/5656704/307157

获取答案