本文介绍了在对象上调用函数时,为什么在非对象上出现此函数调用错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
代码:
public function countDaysWithoutEvents(){
$sql = "SELECT 7 - COUNT(*) AS NumDaysWithoutEvents
FROM
(SELECT d.date
FROM cali_events e
LEFT JOIN cali_dates d
ON e.event_id = d.event_id
WHERE YEARWEEK(d.date) = YEARWEEK(CURRENT_DATE())
AND c.category_id = ?
GROUP BY DAY(d.date)
) AS UniqueDates";
$stmt = $this->link->prepare($sql);
$stmt->bind_param('i', $this->locationID);
$stmt->execute();
$stmt->bind_result($count);
$stmt->close();
return $count;
}
$this->link->prepare($sql)
为MySQLi创建一个准备好的语句.
$this->link->prepare($sql)
creates a prepared statement for MySQLi.
为什么会出现此错误?
推荐答案
AND c.category_id = ?
-查询中没有表别名c.
AND c.category_id = ?
- there is no table alias c in your query.
除了尝试
$stmt = $this->link->prepare($sql);
if (!$stmt) {
throw new ErrorException($this->link->error, $this->link->errno);
}
if (!$stmt->bind_param('i', $this->locationID) || !$stmt->execute()) {
throw new ErrorException($stmt->error, $stmt->errno);
}
这篇关于在对象上调用函数时,为什么在非对象上出现此函数调用错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!