Error:
Fatal error: Call to a member function bind_param() on a non-object in /var/www/web55/web/pdftest/events.php on line 76
Code:
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)
creates a prepared statement for MySQLi.
Why am I getting this error?
AND c.category_id = ?
- there is no table alias c in your query.Besides that try
$this->link->prepare this statement is not returning the object so it is giving you the error
I think the problem is obviously with the prepare function..
The function is probably failing, in which case $stmt would be FALSE and hence not have the bind_param method as a member.
Check your query! Maybe there is a problem with your SELECT statement. And also check for FALSE before trying to execute any member function on what you think is an object returned by the prepare function.
EDIT
I would suspect that the statement may be erroring out because of the sub-query:
Instead, why don't you write your query like this:
P.S. I think you also had a missing a call to fetch as well.. (see example above)