将mysqli_stmt :: get_result()转换为bind_result()

时间:2015-12-05 15:01:31

标签: php mysql methods mysqli

我正在尝试将mysqlnd驱动程序安装到我的服务器上,但我的服务器是在云托管站点上。而且不知道如何启用mysqlnd服务器。 所以我正在尝试另一种方法,使其与当前的php版本兼容。

如何将此get_result方法转换为bind_result。

public function storeUser($name, $email, $password) {
    $uuid = uniqid('', true);
    $hash = $this->hashSSHA($password);
    $encrypted_password = $hash["encrypted"]; // encrypted password
    $salt = $hash["salt"]; // salt

    $stmt = $this->conn->prepare("INSERT INTO users(unique_id, name, email, encrypted_password, salt, created_at) VALUES(?, ?, ?, ?, ?, NOW())");
    $stmt->bind_param("sssss", $uuid, $name, $email, $encrypted_password, $salt);
    $result = $stmt->execute();
    $stmt->close();

    // check for successful store
    if ($result) {
        $stmt = $this->conn->prepare("SELECT * FROM users WHERE email = ?");
        $stmt->bind_param("s", $email);
        $stmt->execute();
        $user = $stmt->get_result()->fetch_assoc();
        $stmt->close();

        return $user;
    } else {
        return false;
    }
}

public function getUserByEmailAndPassword($email, $password) {

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

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

    if ($stmt->execute()) {
        $user = $stmt->get_result()->fetch_assoc();  // m trying to make it bind_result
        $stmt->close();
        return $user;
    } else {
        return NULL;
    }
}

0 个答案:

没有答案