这是我的代码
$stmt = $conn->mysqli->stmt_init();
$stmt = $conn->mysqli->prepare('SELECT Username, EmailVerified, Blocked FROM user WHERE Email = ? AND SLANumber = ? AND Password = ?');
$stmt->bind_param('ssb', $_POST['EmailID'], $_POST['SLANumber'], $_POST['Password']);
$stmt->execute();
$stmt->store_result();
$result = $stmt->get_result();
if($result->num_rows == 0){
echo 'No rows found';
}
else{
// Continue processing here
.....
}
代码总是回显No rows found
.一两天前,它工作正常.
The code always echoes No rows found
. A day or two before, it was working fine.
正如预期的那样,直接运行查询会得到想要的结果.
As expected, running the query directly gives the desired result.
代码有什么问题?
num_rows
是 mysqli_stmt
的属性,而不是结果资源的属性.所以你应该这样做:
num_rows
is a property of mysqli_stmt
, not of a result resource. So you should be doing:
$result = $stmt->get_result();
// Also check strict comparison against int 0,
// to avoid incorrect equality with boolean FALSE
if($stmt->num_rows === 0){
echo 'No rows found';
}
这篇关于MySQLi num_rows 返回 0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!