fetch_object()) { ?> ...-6ren">
gpt4 book ai didi

非对象上的 PHP fetch_object()

转载 作者:行者123 更新时间:2023-11-29 04:09:58 25 4
gpt4 key购买 nike

<?php
$id = $_POST["id"];
$id2 = $_POST["id2"];

$db = new mysqli('localhost', '***', '***', '***');

if (mysqli_connect_errno() == 0) {
$sql = "SELECT * FROM chat_message WHERE id > " . $id . " AND id <= " . $id2 . " ORDER BY id";
$result = $db->query($sql);

while ($msg = $result->fetch_object()) {
?>

<div>...</div>

<?php
}
}

$db->close();
?>

我收到这个错误:

Call to a member function fetch_object() on a non-object in /var/www/template/loadchat.php on line 11

第 11 行:

while ($msg = $result->fetch_object())

有什么帮助吗?因为我从昨天开始就在做这件事,我找不到错误。

最佳答案

1) 验证您的数据库表是否命名为chat_message(也许是chat_messages?)

2) 验证您的 chat_message.id 字段是否存在

3) 验证您的 php 变量 $id$id2 是否为整数/ float !

关于非对象上的 PHP fetch_object(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14440942/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com