本文介紹了簡化:mysqli num_rows 不工作的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
如何使用mysqli輸出返回的行數(shù)?我下面的代碼通過 while 循環(huán)顯示 0 (while $s->fetch() echo $uid;) 顯示 2 個結(jié)果;
$m = new mysqli(MYSQL_SERVER, MYSQL_USER, MYSQL_PASS, MYSQL_DB);$s=$m->prepare("SELECT uid FROM user WHERE token=? AND secret=?");$s->bind_param('ss',$rt, $rs);$rt='c';$rs='d';$s->execute();$s->bind_result($uid);$s->fetch();print_r($s->num_rows);//結(jié)果為 0
解決方案
你必須在 mysqli_stmt::execute()
之后調(diào)用 mysqli_stmt::store_result()
在獲取之前為了知道 mysqli_stmt::num_rows
:
$s->execute();$s->store_result();print_r($s->num_rows);
num_rows
上的 PHP 文檔>
store_result()
上的 PHP 文檔
How do I output the number of returned rows using mysqli? My code below shows 0 though a while loop (while $s->fetch() echo $uid;) shows 2 results;
$m = new mysqli(MYSQL_SERVER, MYSQL_USER, MYSQL_PASS, MYSQL_DB);
$s=$m->prepare("SELECT uid FROM user WHERE token=? AND secret=?");
$s->bind_param('ss',$rt, $rs);
$rt='c';
$rs='d';
$s->execute();
$s->bind_result($uid);
$s->fetch();
print_r($s->num_rows); // RESULTS IN 0
解決方案
You'll have to call mysqli_stmt::store_result()
after mysqli_stmt::execute()
and before fetch in order to know mysqli_stmt::num_rows
:
$s->execute();
$s->store_result();
print_r($s->num_rows);
PHP Document on num_rows
PHP Document on store_result()
這篇關(guān)于簡化:mysqli num_rows 不工作的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!