本文介绍了简化:mysqli num_rows不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用mysqli输出返回的行数?我的下面的代码通过一个while循环显示了0($ s-> fetch()echo $ uid;)显示了2个结果;

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

推荐答案

您必须在mysqli_stmt::execute()之后和提取之前调用mysqli_stmt::store_result()才能知道mysqli_stmt::num_rows:

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);

num_rows

store_result()

这篇关于简化:mysqli num_rows不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 18:58