Using a specific Zend_Db_Table_Abstract to efficiently iterate over a rowset

I am using a specific implementation of Zend_Db_Table_Abstract:

class DB_TestClass extends Zend_Db_Table_Abstract {
    protected $_name = "test.TestData";
}

If I want to select all rows in a table, I have one option:

$t = new DB_TestClass;
$rowset = $t->fetchAll();

This returns an instance of Zend_Db_Table_Rowset, which has an iterative interface that you can loop around and access each row entry as an instance of rowClass:

foreach($rowset as $row) {
    var_dump($row);
}  

HOWEVER, a set of rows loaded each row from the database into memory (!). On small tables, this is normal, but on large tables - for example, in thousands of rows - it quickly runs out of memory available for PHP, and the script dies.

, Zend_Db, , , ala mysql_fetch_assoc()? (, ) .

.

+5
2

fetchAll() , . Zend_Db_Select, , ,

        $select = new Zend_Db_Select ($this->getFrontController()->getParam('bootstrap')->getResource ('Db'));
        $statement = $select->from ('verses')->query ();
        $statement->execute ();


        while ($row = $statement->fetch ())
        {
            // try something like that
            $db_row = new Zend_Db_Table_Row (array ('table' => $table, 'data' => $row));

            $db_row->text = $db_row->text . '_';
            $db_row->save ();

        }
+2

? , - , - . , - , zend_pagination, . . . , fetchAll.

+1

All Articles