0
我想從數據庫中獲取數據。我得到了這個錯誤波紋管。問題是這個代碼在下一個項目中使用,它的工作很好。有人知道問題在哪裏嗎?致命錯誤:調用一個成員函數execute()上的一個非對象在/public_html/website/index.php上線
我得到這個錯誤:
Fatal error: Call to a member function execute() on a non-object in /public_html/website/index.php on line
CODE:
include 'scripts/db_conn.php';
include 'scripts/functions.php';
$prep_stmt = "SELECT date FROM blocked_dates WHERE date >= CURDATE();";
$stmt = $mysqli->prepare($prep_stmt);
$stmt->execute();
if (!$stmt) {
die('There was an error running the query [' . $mysqli->error . ']');
exit();
}
$meta = $stmt->result_metadata();
while ($field = $meta->fetch_field()) {
$parameters[] = & $row[$field->name];
}
call_user_func_array(array($stmt, 'bind_result'), $parameters);
while ($stmt->fetch()) {
foreach ($row as $key => $val) {
$x[$key] = $val;
}
$results[] = $x;
}
「mysqli_prepare()返回一個語句對象或FALSE,如果發生錯誤。」似乎非常清楚準備失敗並返回錯誤。在你認爲是一個有效的語句對象的調用execute之前添加一個檢查。 –