错误在布尔值上调用成员函数fetchAll()

时间:2017-11-17 19:43:26

标签: php mysql

您好,我可以帮助我解决这些错误我得到了他们idk我刚刚进入该网站,我得到了这个错误。

  

致命错误:在布尔值中调用成员函数rowCount()   第6行的C:\ xampp \ htdocs \ settings.php

if (isset($_COOKIE['hash'])) { 
    $sql = $db->query("SELECT * FROM `users` WHERE `hash` = " . $db->quote(filter_var($_COOKIE['hash'], FILTER_SANITIZE_STRING)));
    if ($sql->rowCount() != 0) { //line 6
        $row = $sql->fetch();
        $user = $row;
    }
}
  

致命错误:在布尔值中调用成员函数fetchAll()   第42行的C:\ xampp \ htdocs \ login.php

        $hash = md5($steamid . time() . rand(1, 50)); 
        $sql = $db->query("SELECT * FROM `users` WHERE `steamid` = '" . $steamid . "'");
        $row = $sql->fetchAll(PDO::FETCH_ASSOC); //line 42
        if (count($row) == 0) {

            $name = str_replace("script", "*", $name);
            $name = str_replace("/", "*", $name);
            $name = str_replace("<", "*", $name);
            $name = str_replace(">", "*", $name);
            $name = str_replace("body", "*", $name);
            $name = str_replace("onload", "*", $name);
            $name = str_replace("alert", "*", $name);
            $name = str_replace(")", "*", $name);
            $name = str_replace("(", "*", $name);
            $name = str_replace("'", "*", $name);

1 个答案:

答案 0 :(得分:-1)

绝对没有理由假设您的查询将始终成功执行。你的罪过是没有错误处理,这意味着没有检查query()返回的内容。并通过文档返回:

PDO::query() returns a PDOStatement object, or FALSE on failure.

所以,当你得到boolean时,它显然意味着你的查询失败了。