【问题标题】:php mysqli bind_result returns 1php mysqli bind_result 返回 1
【发布时间】:2017-01-07 00:15:46
【问题描述】:

您好,我正在尝试使用在 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;
    }
}

【问题讨论】:

  • 你正在打印fetch()的返回,如果成功则为true/1。

标签: php android mysql mysqli


【解决方案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();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-08-19
    • 1970-01-01
    • 2011-04-06
    • 2011-05-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多