【问题标题】:Error: Call to undefined method mysqli_stmt::fetch_object()错误:调用未定义的方法 mysqli_stmt::fetch_object()
【发布时间】:2023-04-10 15:36:01
【问题描述】:

我试图让这个 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) {... ?>

我做错了什么?

【问题讨论】:

标签: php


【解决方案1】:

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

从这个https://stackoverflow.com/a/5656704/307157得到答案

【讨论】:

    猜你喜欢
    • 2014-01-09
    • 1970-01-01
    • 1970-01-01
    • 2013-06-02
    • 1970-01-01
    • 2022-01-11
    • 2014-12-23
    相关资源
    最近更新 更多