gpt4 book ai didi

php - 为什么这种使用 PDO 统计 Mysql 行数的方法不起作用?

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

<分区>

我正在尝试使用 PDO 计算从 SELECT 语句返回的行数。

$stmt = $dbh->prepare("SELECT * FROM posts WHERE cat_id= ?");
$stmt->bindParam(1,$cat_id);
$stmt->execute();

$rows = $stmt->fetchAll();
$count_posts = count($rows);
return $count_posts;

我使用 fetchAll() 然后使用 count() 来计数,但它不起作用。当我回显它时,它回显 0。我认为数组是 $rows$count_posts 将是该数组的计数?

echo $count_posts = count_cat_posts($cat_id);

谢谢

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