如何使用预先准备的语句获取mysqli_fetch_array
?我试过fetch_assoc()
但是我总是收到一个错误,告诉我fetch_assoc()
没有定义。我如何使其发挥作用?
$query = "SELECT * FROM users WHERE
username = ? AND
pass = ? LIMIT 1";
$stmt = $_SESSION['connessione']->prepare($query);
$stmt->bind_param('ss', $username, $password);
$stmt->execute();
$stmt->store_result();
if($stmt->num_rows == 1){
$row = $stmt->fetch_assoc();
// originally it was like this $row = mysqli_fetch_array($result);
// where $result was the query result
$this->login_iduser = $row['id'];
$this->login_profile_pic = $row['pic'];
$this->login_privileges = $row['admin'];
return TRUE;
}
return FALSE;
如您所见,我需要找到$row
数组。
答案 0 :(得分:1)
您必须安装MySQLND才能执行此操作。 mysqli
准备好的语句本身不会产生mysqli_result
个对象。您需要使用get_result
$stmt->execute();
$result = $stmt->get_result();
if($result->num_rows == 1){
$row = $result->fetch_assoc();