如何使用mysqli输出返回的行数?下面的代码显示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
答案 0 :(得分:5)
您需要在mysqli_stmt::store_result()
之后和之前致电mysqli_stmt::execute()
,以便了解mysqli_stmt::num_rows
:
$s->execute();
$s->store_result();
print_r($s->num_rows);