Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
$stmt = $conn->prepare('select count(names) as names from names where names = :name'); $stmt->bindParam(':name', $name); $stmt->execute();
如何在select count()使用 PDO 时输出名称的值,而不必使用 while 循环或类似的东西?
select count()
我需要名称的计数值(1、3 或 5 或其他)。
-Statementselect count(..) from ..始终只输出此列(行数),因此您无法访问名称。您只需要执行一个语句来获取名称,或者您可以自己实际输出名称,因为您已经拥有它$name;)
select count(..) from ..
$name
$count = $stmt->fetchColumn();
取列()