gpt4 book ai didi

php - 简化: mysqli num_rows not working

转载 作者:行者123 更新时间:2023-11-29 21:17:29 25 4
gpt4 key购买 nike

如何使用 mysqli 输出返回的行数?我下面的代码显示 0,尽管 while 循环 (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

最佳答案

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

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

PHP Document on num_rows

PHP Document on store_result()

关于php - 简化: mysqli num_rows not working,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35847285/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com