为什么PDO fetchColumn()在这里不起作用 [英] Why is PDO fetchColumn() not working here
本文介绍了为什么PDO fetchColumn()在这里不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图计算查询返回的行数,并且这样做:
I'm trying to count the number of rows returned by a query, and I'm doing like this:
$what = 'Norman';
$stmt = $conn->prepare('select names as names from names where names = :what');
$stmt->bindParam('what', $what);
$stmt->execute();
$rows = $stmt->fetchColumn();
echo 'Rows found '.$rows;
$stmt->setFetchMode(PDO::FETCH_ASSOC);
while($row = $stmt->fetch())
{
echo $row['names'] . "<br>";
}
但是我什么也没得到.只是空白.正确的方法是什么?
But I keep getting nothing at all. Just blank. Whats the right way to do this?
推荐答案
If you want to get the number of rows returned use rowCount
// ...
$rows = $stmt->rowCount();
echo 'Rows found '.$rows;
// ...
这篇关于为什么PDO fetchColumn()在这里不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文