While queryScalar is useful for fetching scalar values in queries like
SELECT count(*), it cannot be used with prepared statements in PDO.
DatabaseResult::fetchScalar returns the first item of the next row.
The following fluent pattern is now supported:
$sql = "SELECT count(*) FROM foo WHERE id = :id";
return $this->db
->prepare($sql)
->with("id", $this->id)
->query()
->fetchScalar();fetchScalar is implemented at DatabaseResult level, making it available
with all drivers, not just PDO.
Ref T2169