Search code examples
zend-frameworkzend-dbzend-db-table

Zend Framework DB table fetch array


is it possible to fetch array from db, taking one column as array key and other column as array value?

My current code:

$table = new Zend_Db_Table('translations');

$where = $table->getAdapter()->quoteInto('lang = ?', $locale);      

$result = $table->fetchAll($where)->toArray();

Table structure:

id     key     lang     title
1      key1    en       Some english text
2      key2    de       Some german text

So after fetching an array I would like to get array that contains key value as a array key, and a title as a array key value.

Your help would be appreciated.


Solution

  • If you need pairs, it's better to do like this

    $table = new Zend_Db_Table ('translations');
    $db = $table->getAdapter();
    $select = $table->select ()
        ->columns(array('key','title'))
        ->where ('lang = ?', $locale);
    $result = $db->fetchPairs($select);