我正在尝试SELECT使用 PDO 计算从语句返回的行数。
$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);
谢谢