当我关闭连接时,出现此错误:
PHP警告:无法获取mysqli_result
此错误:
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
任何帮助将不胜感激。谢谢:)
答案 0 :(得分:0)
尝试在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