donglang6656 2016-08-22 16:02
浏览 30

如何修复调用成员函数prepare()对字符串[duplicate]

This question already has an answer here:

I have been trying to fix this error: PHP Fatal error: Call to a member function prepare() on string in /home/...../lib/library.php on line 91 I have also check this link: Reference - What does this error mean in PHP? and i don't seem to understand how to relate it to my problem at hand. Can anyone help? this is the script line affected:

public function Login($username, $password)
    {
        try {
            $db = DB();
            $query = $db->prepare("SELECT user_id FROM users WHERE (username=:username OR email=:username) AND password=:password");
            $query->bindParam("username", $username, PDO::PARAM_STR);
            $enc_password = hash('sha256', $password);
            $query->bindParam("password", $enc_password, PDO::PARAM_STR);
            $query->execute();
            if ($query->rowCount() > 0) {
                $result = $query->fetch(PDO::FETCH_OBJ);
                return $result->user_id;
            } else {
                return false;
            }
        } catch (PDOException $e) {
            exit($e->getMessage());
        }
    }
</div>
  • 写回答

1条回答 默认 最新

  • dongwuwei0718 2016-08-22 16:04
    关注

    Your problem is here:

    $db = DB();
    

    If you were to var_dump() the $db variable you'd see it is equal to a string with a value of something like DB or DB().

    It should be:

    $db = new DB();
    
    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?