[英]simplified: mysqli num_rows not working
How do I output the number of returned rows using mysqli?如何使用mysqli输出返回的行数? My code below shows 0 though a while loop (while $s->fetch() echo $uid;) shows 2 results;我下面的代码通过 while 循环显示 0 (while $s->fetch() echo $uid;) 显示 2 个结果;
$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
:您必须在mysqli_stmt::execute()
和 fetch 之前调用mysqli_stmt::store_result()
才能知道mysqli_stmt::num_rows
:
$s->execute();
$s->store_result();
print_r($s->num_rows);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.