title: How to get the total number of rows of a GROUP BY query?
body: <p>From the PDO manual:</p>
  
  <blockquote>
    <p>PDOStatement::rowCount() returns the
    <strong>number of rows</strong> affected by the last
    <strong>DELETE, INSERT, or UPDATE</strong> statement
    executed by the corresponding
    PDOStatement object.</p>
    
    <p>If the last SQL statement executed by
    the associated PDOStatement was a
    <strong>SELECT</strong> statement, <strong>some databases may
    return the number of rows returned by
    that statement</strong>. However, this
    behaviour is <strong>not guaranteed for all
    databases</strong> and should not be relied on
    for portable applications.</p>
  </blockquote>
  
  <p>I found that out only very recently. I had just changed my db abstraction layer to not use <code>SELECT COUNT(1) ...</code> anymore, because just quering the actual rows and then counting the result would be much more efficient. And now PDO doesn't support that!?</p>
  
  <p>I don't use PDO for MySQL and PgSQL, but I do for SQLite. Is there a way (without completely changing the dbal back) to count rows like this in PDO? In MySQL, this would be something like this:</p>
  
  <pre><code>$q = $db-&gt;query('SELECT a, b, c FROM tbl WHERE oele = 2 GROUP BY boele');
  $rows = $q-&gt;num_rows;
  // and now use $q to get actual data
  </code></pre>
  
  <p>With the MySQLi and PgSQL drivers, this is possible. With all PDO it isn't!?</p>
  
  <p>PS. My initial solution was to extend the SQLResult->count method (my own) to replace <code>SELECT ... FROM</code> by <code>SELECT COUNT(1) FROM</code> and just return that number (very inefficient, but only for SQLite PDO). That's not good enough though, because in the example query above is a <code>GROUP BY</code>, which would change the meaning/function of the <code>COUNT(1)</code>.</p>