Using Doctrine DBAL to count number of rows from SELECT query
Actually I thought I had looked really hard, but I just came across this Count Records Returned MySQL Doctrine
So the way to do it is via the rowCount()
method.
Example:
$num_rows = $conn->executeQuery("SELECT * FROM users")->rowCount();
Another way to do this with Doctrine DBAL is to get the count as a field and return the column
$sql = "SELECT count(*) AS Total FROM myTable WHERE myId = :myId";
$stmt = $conn->prepare($sql);
$stmt->bindValue('myId', $myId, PDO::PARAM_INT);
$stmt->execute();
$count = $stmt->fetchColumn(0);