The only way that databases can give you a count for the number of rows is by running the query and counting the number of rows.
The mysql extension uses a buffered query mode by default that causes the entire dataset to be fetched into memory before control is returned to PHP and it can start to process the rows.
PDO uses an unbuffered mode by default which leads to lower latency in the page load time and is generally what you want. The trade off is that rowCount() won't return valid information until the entire dataset has been fetched.
So how do you get that count?
Easy:
$q = $db->query("SELECT ...");
$rows = $q->fetchAll();
$rowCount = count($rows);
echo "There are $rowCount rows\n";
foreach ($rows as $row) {
print_r($row);
}
But that sucks because it queries all the rows up front and makes my page load slower, the old mysql extension didn't have this problem!?
But that's exactly what the old mysql extension is actually doing under the covers; it's the only way to get that count.