替代mysqli_stmt :: fetch_array()的OOP

时间:2017-01-03 15:19:50

标签: php oop mysqli

我是OOP PHP的新手,并且正在努力理解使用的替代方法:

$stmt->fetch_array(MYSQLI_ASSOC);

这一行似乎是以下示例中的罪犯:

<?php
include '../config.php';
ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL);


// Collect the form inputs
$email = $_POST['email']; 
$password = $_POST['password'];


// Prepare and store the inputs client side
if($stmt = $conn->prepare("SELECT * FROM users WHERE email = ?")) 
{ 
    $stmt->bind_param("s", $email); 
    $stmt->execute(); 
    $stmt->store_result(); 
}

// Check if the user exists
if($stmt->num_rows === 1)
{
    $row = $stmt->fetch_array(MYSQLI_ASSOC);

    if (password_verify($password, $row['password'])) 
    {

        // Passing sesion data through for us to use

        $_SESSION['id'] = $row[ 'user_id'];
        $_SESSION['email'] = $row[ 'user_email']; 

        header("Location: index.php");

     }

}
else 
{
    echo 'Something has gone wrong';
}

// Close and clense any open connections
$stmt->close(); 
$conn->close();
?>

我正在试图理解准备好的陈述,这条线让我有些悲伤!

我试图自己寻找孤子,许多文章建议使用mysqli_stmt::fetch(),但这只是服务500

我的问题是为$row变量分配数组的正确方法是什么,因为在使用上述内容时我会收到错误。

启用错误后,我看到以下错误:

Fatal error: Call to undefined method mysqli_stmt::fetch_array()

0 个答案:

没有答案