php mysqli bind_result返回1

时间:2017-01-07 00:15:46

标签: php android mysql mysqli

您好我正在尝试使用在ec2实例上运行的android和php创建一个登录应用程序,但即使我输入了正确的凭据,我也无法登录。
所以我开始打印查询,如果我打印$ user,我得到的是“1”任何建议吗?

public function getUserByEmailAndPassword($email, $password) {

    $stmt = $this->conn->prepare("SELECT * FROM users WHERE email=?"); 
    $stmt->bind_param('s', $email);
    if ($stmt->execute()) {
        $stmt->bind_result($id,$unique_id,$name,$email,$encrypted_password,$salt,$created_at,$updated_at);
        $user = $stmt->fetch();
        $stmt->close();     

        // verifying user password
        $salt = $user['salt'];
        $encrypted_password = $user['encrypted_password'];
        $hash = $this->checkhashSSHA($salt, $password);
        // check for password equality
        if ($encrypted_password == $hash) {
            // user authentication details are correct
            return $user;
        }
    } else {
        return null;
    }
}

1 个答案:

答案 0 :(得分:1)

当您使用bind_result时,您将获得与bind_result绑定的变量中的数据。

$stmt->bind_result($id,$unique_id,$name,$email,$encrypted_password,$salt,$created_at,$updated_at);
$stmt->fetch();
echo $unique_id;
$stmt->close();