Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Zend_Db_Table - Associative Array Instead Of Object

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)?

like image 496
Richard Knop Avatar asked Aug 24 '09 23:08

Richard Knop


2 Answers

$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.

like image 131
Bill Karwin Avatar answered Sep 24 '22 21:09

Bill Karwin


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);
like image 38
asgeo1 Avatar answered Sep 26 '22 21:09

asgeo1