duanshan188866 2012-06-14 15:01
浏览 81
已采纳

查询返回null

Hello I've got this query to get users by email, which is an unique field in the db.

However, when i want to get the data on it, it simply returns null.

Here's the code

    public function getUserByEmail($email)
    {

            $statement = "SELECT id_user,nome,email,permissao,activo FROM sys_users 
                          WHERE email=$email";

            try
            {

             $sth = $this->db->query($statement);
             $sth->setFetchMode(PDO::FETCH_OBJ);
             $rcs_users = $sth->fetchAll();
             return $rcs_users;

            }
            catch(PDOException $e)
            {
                "DB Error".$e->getMessage();
            }

    }

And the respective function call

$user_rcs = $user->getUserByEmail($email);

    var_dump($user_rcs); //returns null




    $_SESSION['email'] = $email;
    $_SESSION['user'] = $user_rcs->nome;
    $_SESSION['permissao'] = $user_rcs->permissao;

And then I get this error

Notice: Trying to get property of non-object in C:\xampp\htdocs\inacesso\admin\modules\auth\authhandler.php on line 24

Glad if you could help me!

  • 写回答

2条回答 默认 最新

  • dounei9043 2012-06-14 15:04
    关注

    First off, seriously have a look at PDO.

    Secondly I would imagine the email column is a string. As such, you'll need to surround $email with quotes in your query (after having sanitized it vigorously of course...)

    WHERE email='$email'
    

    PDO version:

    $pdo = new PDO(...);
    $query = $pdo->prepare('SELECT id_user,nome,email,permissao,activo '.
                           'FROM   sys_users '.
                           'WHERE  email = ?');
    $result = $query->execute(array($email));
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 为什么apriori的运行时间会比fp growth的运行时间短呢
  • ¥15 帮我解决一下膳食平衡的线性规划模型的数据实例
  • ¥40 万年历缺少农历,需要和阳历同时显示
  • ¥250 雷电模拟器内存穿透、寻基址和特征码的教学
  • ¥200 比特币ord程序wallet_constructor.rs文件支持一次性铸造1000个代币,并将它们分配到40个UTXO上(每个UTXO上分配25个代币),并设置找零地址
  • ¥15 关于Java的学习问题
  • ¥15 如何使用chatgpt完成文本分类任务?
  • ¥15 已知速度v关于位置s的等式,怎么转化为已知位置求速度v的等式
  • ¥15 我有个餐饮系统,用wampserver把环境配置好了,但是后端的网页却进去,是为什么,能不能帮远程一下?
  • ¥15 R运行没有名称为"species"的插槽对于此对象类"SDMmodelCV"