我想从数据库中获取数据。下面我得到了这个错误。问题是这个代码在我的其他项目中使用并且它工作得很好。有人知道问题出在哪里吗?
我收到了这个错误:
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;
}
答案 0 :(得分:0)
您无法将对象绑定到新变量。
尝试像这样开始你的代码:
$stmt = new Mysqli();
连接数据库后,
$stmt->prepare($prep_stmt);
$debug = $stmt->execute();
if (!$debug) {
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;
}