如何用bind_param()替换get_result() - > fetch_Assoc()以保持相同的结构

时间:2017-03-31 17:30:47

标签: php mysql

我有来自教程的代码,但我的数据库不支持get_result()。我已经读过您可以使用bind_param()更改它,但我不太确定它是如何工作的。而且我不知道如何在我的情况下应用它

public function getUserByEmailAndPassword($email, $password) {

        $stmt = $this->conn->prepare("SELECT * FROM tbl_login WHERE email = ?");

        $stmt->bind_param("s", $email);

        if ($stmt->execute()) {

            $user = $stmt->get_result()->fetch_assoc();

            $stmt->close();

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

如何更改$user = $stmt->get_result()->fetch_assoc();行以使其仍然可以正常工作?

0 个答案:

没有答案
相关问题