使用mySql在php pdo中输出选择计数(名称)值

时间:2013-05-03 06:46:36

标签: php pdo

$stmt = $conn->prepare('select count(names) as names from names where names = :name');
$stmt->bindParam(':name', $name);
$stmt->execute();

在使用PDO执行select count()时如何输出名称的值而不必使用while循环或类似的东西?

我需要名字的计数值(1,3或5或其他任何东西)。

2 个答案:

答案 0 :(得分:1)

select count(..) from .. - 语句始终只输出此列(行数),因此您无法访问这些名称。您只需要为获取名称而执行一个语句,或者您可以自己输出名称,因为您已经在$name中拥有该名称;)

答案 1 :(得分:1)

$count = $stmt->fetchColumn();

fetchColumn()