The following line:
$select = $table->select();
$select->where('approved = 1');
$result = $table->fetchRow($select);
Returns an object. What I would like is to get an associative array instead.
I know that Zend_Db has fetchAssoc() method for that but is something similar also in the Zend_Db_Table (I tried fetchAssoc() but it doesn't work, I haven't found anything in the documentation)?
$result = $table->fetchRow($select)->toArray();
Both Zend_Db_Table_Row
and Zend_Db_Table_Rowset
have a toArray()
method. A Row is returned as an associative array, and a Rowset is returned as a simple (ordinal) array of associative arrays.
To further Bill's answer, if you wanted the Rowset returned as an associative array (rather than ordinal) the only choice appears to be Zend_Db (as you alluded to):
$db = $table->getAdapter();
$select = $table->select();
$select->where('approved = 1');
$result = $db->fetchAssoc($select);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With