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

Categories

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

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

1 Answer

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...