2

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

1 回答 1

5

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

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

PHP 文档在num_rows

PHP 文档在store_result()

于 2012-11-02T03:19:05.973 回答