In some case you need to know how many row are retrieved from a select query (i.e to page a result set) you can use:
$totalRows = count($resultSet->fetchAll());
It works on MySQL 5.0.18 and PHP 5.1
![]() | PDOStatement::rowCount(no version information, might be only in CVS) PDOStatement::rowCount -- Returns the number of rows affected by the last SQL statement说明int PDOStatement::rowCount ( void )PDOStatement::rowCount() returns the number of rows affected by the last DELETE, INSERT, or UPDATE statement executed by the corresponding PDOStatement object. If the last SQL statement executed by the associated PDOStatement was a SELECT statement, some databases may return the number of rows returned by that statement. However, this behaviour is not guaranteed for all databases and should not be relied on for portable applications. 范例
![]()
pcdinh at phpvietnam dot net
21-Mar-2006 06:39
In some case you need to know how many row are retrieved from a select query (i.e to page a result set) you can use:
Pablo Godel
31-Jan-2006 04:18
For large resultsets the method described below is not very efficient. It is better to do a select COUNT(*).
markjcrane at gmail dot com
30-Nov-2005 08:12
A rowcount that would return the record count with a select statement would be extremely usefull in PDO. However since it doesn't exist here is an another method to return the record count. | ![]() | |||