在布尔值上调用成员函数 fetchAll() [英] Call to a member function fetchAll() on boolean

查看:60
本文介绍了在布尔值上调用成员函数 fetchAll()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下问题.

这个错误一直伴随着我

<块引用>

致命错误:未捕获的错误:调用 C:\xampp\htdocs\certificado\functions.php:49 中布尔值的成员函数 fetchAll() 堆栈跟踪:#0 C:\xampp\htdocs\certificado\index.php(11): get_info_from_email('amanda_pandoka@...') #1 {main} 在第 49 行的 C:\xampp\htdocs\certificado\functions.php 中抛出

在下面的代码中,我无法理解错误.有人可以帮我吗?

 函数连接() {$socket = new PDO('mysql:host=' .@$host .';dbname=' .@$nomedobancodedados,@$usuario, @$senha);$socket->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);返回 $socket;}函数 get_info_from_email($email) {如果 (!$email)返回假;全球 $db;$sql = "选择ID,名称,电子邮件,类型,数据,文件从参加者哪里 1=1AND email = '{$email}'";if ($info = $db->query($sql))返回假;if ($info = $info->fetchAll())返回假;返回 $info;}

解决方案

继续这样<预>

<代码>

 function get_info_from_email($email) {如果 (!$email) {返回假;}全球 $db;$sql = $db->prepare("选择ID,名称,电子邮件,类型,数据,文件从参加者哪里 1=1AND 电子邮件 = :email");print_r($db->e​​rrorInfo());//如果查询无法执行,则返回 falseif (!$sql->execute(array(':email' => $info))) {返回假;}//如果在检索查询结果时出现**错误**,则返回 falseif (($info = $sql->fetchAll()) === false) {返回假;}返回 $info;

}

I have the following problem.

This error persisting in accompanying me

Fatal error: Uncaught Error: Call to a member function fetchAll() on boolean in C:\xampp\htdocs\certificado\functions.php:49 Stack trace: #0 C:\xampp\htdocs\certificado\index.php(11): get_info_from_email('amanda_pandoka@...') #1 {main} thrown in C:\xampp\htdocs\certificado\functions.php on line 49

In the code below I can not understand the error. Can someone help me?

    function connect() {
    $socket = new PDO('mysql:host=' . @$host . ';dbname=' . @$nomedobancodedados,
        @$usuario, @$senha);
    $socket->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
    return $socket;
}

function get_info_from_email($email) {

    if (!$email)
        return false;

    global $db;

    $sql = "
        SELECT
            id,
            name,
            email,
            type,
            data,
            file
        FROM
            attendee
        WHERE 1=1
            AND email = '{$email}'
    ";
    if ($info = $db->query($sql))
        return false;

    if ($info = $info->fetchAll())
        return false;

    return $info;

    }

解决方案

Continue like this

 function get_info_from_email($email) {
if (!$email) {
    return false;
}

global $db;

$sql = $db->prepare("
    SELECT
        id,
        name,
        email,
        type,
        data,
        file
    FROM
        attendee
    WHERE 1=1
        AND email = :email
");
print_r($db->errorInfo());
// return false if the query cannot be executed
if (!$sql->execute(array(':email' => $info))) {
    return false;
}

// return false if there was an **error** retrieving the query results
if (($info = $sql->fetchAll()) === false) {
    return false;
}

return $info;

}

这篇关于在布尔值上调用成员函数 fetchAll()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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