Following on from my previous post, another common variant on the SELECT statement is SELECT COUNT. For instance:
SELECT COUNT(*) FROM order WHERE status = 'ordered'
This statement returns the number of records in the order table where the status field is set to ordered.
To perform this query using Zend_Db_Select, we would use something like:
$select = $dbTable->select(); $select->from($dbTable, array('count(*) as c')); $rows = $dbTable->fetchAll($select); $count = $rows->c;
Note that we alias the result of the account as c in order to make retrieval easier.