有时返回值,有时返回bool(false)

时间:2016-09-01 12:59:54

标签: php sql mysqli multiple-columns

这一个返回布尔(假)

function authenticate($user, $pass){
        $sql  = "SELECT * FROM Users ";
        $sql .= " WHERE UniqueUser = \"{$user}\" ";
        $sql .= " AND HashedPass = \"{$pass}\" ";
        $sql .= " LIMIT 1";

        $result = mysqli_query($sql);
        $result_set = mysqli_fetch_array($result);
        return !empty($result_set) ? array_shift($result_set) : false;
}

如果搜索任何其他数据库列,如firstname,则返回lastname 整行,一切进展顺利

function authenticate($user, $pass){
        $sql  = "SELECT * FROM Users ";
        $sql .= " WHERE LastName= \"{$user}\" ";
        $sql .= " AND HashedPass = \"{$pass}\" ";
        $sql .= " LIMIT 1";

        $result = mysqli_query($sql);
        $result_set = mysqli_fetch_array($result);
        return !empty($result_set) ? array_shift($result_set) : false;
}

为什么有些列有时候没有按预期工作?

0 个答案:

没有答案