关闭mysqli连接产生:无法获取mysqli\u结果

eqoofvh9  于 2021-06-15  发布在  Mysql
关注(0)|答案(1)|浏览(270)

当我关闭连接时,出现以下错误:
php警告:无法获取mysqli\u结果
这个错误是:
php警告:还不允许访问属性
我已经确保在循环外关闭连接,但是无论我在哪里放置断点,错误的行号都会改变。
我的php代码在这里:

$sql = "SELECT arrivalDate, departDate FROM holidayletdatabase.bookings 
WHERE departDate > '$current_date'";
if ($result = $connect->query($sql)) {
    while ($obj = $result->fetch_object()) {
        array_push($bookings, $obj);
    }
    $result->close();
}
$connect->close(); //closes the connection

任何帮助都将不胜感激。谢谢:)

vc6uscn9

vc6uscn91#

在if语句中使用$result之前,请先尝试定义它:

$sql = "SELECT arrivalDate, departDate FROM holidayletdatabase.bookings 
WHERE departDate > '$current_date'";
$result = $connect->query($sql);
if ($result) {
    while ($obj = $result->fetch_object()) {
        array_push($bookings, $obj);
    }
    $result->close();
}
$connect->close(); //closes the connection

相关问题