本文介紹了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_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模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!