[英]PHP getting the number of results returned from DB with stored procedure
我正在尝试使用mysqli_num_rows从数据库中获取结果数,但是我不知道要传递什么参数,因为我正在使用存储过程。 我将发布我的工作。 在我当前的代码中,执行Else。 我是PHP的新手。
<?php
session_start();
include_once 'constants.php';
include_once 'connection.php';
$connection = new database();
$connection->connect();
$email = $_POST['email'];
$password = $_POST['password'];
// Call the login stored procedure
$conn = $connection->query("CALL LoginUser('$email','$password')");
//Check if any users match
$rows = mysqli_num_rows($conn);
if($rows > 0){
// If result was found put information into array
$user = mysqli_fetch_assoc($conn);
//Store all the users info in session variables
$_SESSION['user_id'] = $user['account_id'];
$_SESSION['user_firstName'] = $user['fname'];
$_SESSION['user_lastName'] = $user['lname'];
$_SESSION['user_password'] = $user['password'];
$_SESSION['user_dob'] = $user['dob'];
$_SESSION['user_joinDate'] = $user['joinDate'];
$_SESSION['user_picture'] = $user['picture'];
//Redirect user to logged in home page
header('Location: home.php');
// If no results are found redirect user to noAccount page
} else {
header('Location: noAccount.php');
}
?>
$user = mysqli_fetch_assoc($conn);
if(!empty($user) > 0){
//Store all the users info in session variables
$_SESSION['user_id'] = $user['account_id'];
$_SESSION['user_firstName'] = $user['fname'];
$_SESSION['user_lastName'] = $user['lname'];
$_SESSION['user_password'] = $user['password'];
$_SESSION['user_dob'] = $user['dob'];
$_SESSION['user_joinDate'] = $user['joinDate'];
$_SESSION['user_picture'] = $user['picture'];
//Redirect user to logged in home page
header('Location: home.php');
// If no results are found redirect user to noAccount page
} else {
header('Location: noAccount.php');
}
mysqli_num_rows
期望输出结果。
编辑: num_rows
期望查询结果而不是获取的结果。 在这种情况下,我建议您使用我修改过的上述代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.