MySQLi num_rows 返回 0 [英] MySQLi num_rows returns 0

查看:28
本文介绍了MySQLi num_rows 返回 0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码

$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_rowsmysqli_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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆