我正在尝试为我的登录表单使用prepare语句(第一次)。我得到num_row为1,但我没有得到任何与get_result()。任何人都可以帮我弄清楚我做错了什么? 这是我的代码:
public function login($username, $password) {
$db = new DB();
$conn = $db->connect();
$encPass = md5($password);
$sql = "SELECT * FROM users WHERE username = ? AND password = ?";
$stmt = $conn->prepare($sql);
$stmt->bind_param('ss',$username,$encPass);
$stmt->execute();
$stmt->store_result();
$row_count = $stmt->num_rows;
echo "Number of rows: ".$row_count."<br>";
$result = $stmt->get_result();
if(!$result){
die("error in receiving data ".$stmt->error." Error no. - ". $stmt->errno);
}
if($row_count == 1)
{
$_SESSION["user"] = serialize(new User($result->fetch_assoc()));
$_SESSION["login_time"] = time();
$_SESSION["logged_in"] = 1;
return true;
}else{
return false;
}
}
结果如下:
行数:1
接收数据时出错错误号。 - 0