在对象上调用函数时,为什么在非对象上出现此函数调用错误? [英] Why do I get this function call error on an non-object when I am calling a function on an object?

查看:45
本文介绍了在对象上调用函数时,为什么在非对象上出现此函数调用错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

致命错误:调用成员函数 在非对象中的bind_param() /var/www/web55/web/pdftest/events.php 在第76行

Fatal error: Call to a member function bind_param() on a non-object in /var/www/web55/web/pdftest/events.php on line 76

代码:

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);
}

这篇关于在对象上调用函数时,为什么在非对象上出现此函数调用错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆