dpxf81245 2014-09-08 06:52
浏览 50
已采纳

致命错误:在非对象上调用成员函数bind_param()

I try some codes to build a RESTful API Web Service using PHP and slim framework. (I'm using Advanced Rest Client for testing this code)

This is my codes.

private function isUserExists($email) { $stmt = $this->conn->prepare("SELECT id from users WHERE email = ?"); $stmt->bind_param("s", $email); $stmt->execute(); $stmt->store_result(); $num_rows = $stmt->num_rows; $stmt->close(); return $num_rows > 0; }

and then I got this error.

Fatal Error : Call to a member function bind_param() on a non-object on Line 113

Line 113 is : $stmt->bind_param("s", $email);

I've been looking for a solution of this problem since 2 weeks ago.

Thanks before guys :))

  • 写回答

1条回答 默认 最新

  • dousao1175 2014-09-08 07:00
    关注

    The problem lies in $this->conn->prepare, which does not return an object, as you would expect.

    For mysqli, prepare() returns FALSE on error. You can check the error message using $this->conn->error.

    This code should print your error in case of failure:

    private function isUserExists($email) {
        $stmt = $this->conn->prepare("SELECT id from users WHERE email = ?");
        if ($stmt === FALSE){
            die($this->conn->error);
        } else  {
            $stmt->bind_param("s", $email);
            $stmt->execute();
            $stmt->store_result();
            $num_rows = $stmt->num_rows;
            $stmt->close();
            return $num_rows > 0;
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 在若依框架下实现人脸识别
  • ¥15 网络科学导论,网络控制
  • ¥100 安卓tv程序连接SQLSERVER2008问题
  • ¥15 利用Sentinel-2和Landsat8做一个水库的长时序NDVI的对比,为什么Snetinel-2计算的结果最小值特别小,而Lansat8就很平均
  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同