Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
812 views
in Technique[技术] by (71.8m points)

php - simplified: mysqli num_rows not working

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
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

PHP Document on num_rows

PHP Document on store_result()


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...