php - php 错误:在布尔值上调用成员函数 fetch_assoc()
问题描述
我编写了一个非常简单的 php 脚本,目标是连接到 mysql 数据库,检索数据并回显数据。脚本如下:
<?php
// Include config file
require_once 'config.php';
// Prepare a select statement
$get_query = "select * from dishes";
$stmt = $mysqli->prepare($get_query);
$stmt->execute();
$stmt->store_result();
$result = $stmt->get_result();
//create array to put the table in
$response = array();
$response['dishes'] = array();
while($dishes = $result->fetch_assoc()){
//create a temporary array
$temp = array();
//inserting the dishes in the temporary array
$temp['unique_id'] = $dishes['unique_id'];
$temp['title']=$dishes['title'];
//push the temporary array inside response
array_push($response['dishes'],$temp);
}
echo json_encode($response);
?>
在配置文件中是连接到我的数据库所必需的东西。餐桌菜肴非常简单,它有 2 列,一列用于 unique_id,另一列带有标题。该脚本是不言自明的,因为我在其中补充了评论。但是如果我运行它,我会收到以下错误:
PHP 致命错误:未捕获的错误:在布尔值中调用成员函数 fetch_assoc()
点指向此文件的位置。我不明白为什么会这样。谢谢!
解决方案
消除
$stmt->store_result();
推荐阅读
- c++ - 有没有更简单的方法从后面遍历向量?
- c# - 接口和重载
- c# - 如何在 C# 中对两个 JSON 数组进行排序和比较?
- node.js - 带有ipc的Windows上的节点child_process.spawn错误文件描述符
- qt - 何时调用异步 QMenu::popup() 与同步 QMenu::exec()?
- python-3.x - tkinter 在绑定到 double_click 事件时出现意外行为 - 什么是双击?
- tensorflow - 卷积层过滤器在 Keras 中显示
- amazon-web-services - 使用 Hadoop s3a 从 spark 作业写入 s3 时,指定的加密方法不受支持错误
- c# - 更改 FolderBrowserDialog 的设计
- firebase - Firebase httpsCallable 与“允许未经身份验证”的云功能