I worked on the Zend_Db component quite a bit when I was on the Zend Framework project (up until ZF 1.0).
As @netcoder says, the Zend_Db_Table component creates objects for each row fetched. Objects take more memory than primitive arrays, but they also give you the opportunity to use the OO usage and save()
etc.
The real trouble is that you're doing fetchAll()
on a large data set. Even if your memory limit could handle 22000 rows, tomorrow you will need 44000 rows, and next month 100000 rows.
Regardless of the Zend_Db implementation, or if you use PDO with no framework, you need to learn to manage large data sets without loading them completely into memory, because that will inevitably lead to memory exhaustion. This is true for any library or framework or even any language.
You can try using LIMIT
as @Chris Henry suggests, so you are sure to fetch a fixed quantity of rows that is not too much.
Alternatively, you can fetch the data a row at a time so you only have one row in memory. The Zend_Db_Table class does not provide a means to do this; you'll have to run SQL queries yourself with the Zend_Db_Adapter interface and then loop over the results with fetch()
.
See examples at http://framework.zend.com/manual/en/zend.db.statement.html