简化:mysqli num_rows不起作用

时间:2012-11-02 02:53:12

标签: php mysql mysqli

如何使用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

1 个答案:

答案 0 :(得分:5)

您需要在mysqli_stmt::store_result()之后和之前致电mysqli_stmt::execute(),以便了解mysqli_stmt::num_rows

$s->execute();
$s->store_result();
print_r($s->num_rows);

PHP Document on num_rows

PHP Document on store_result()