0

I would like to change the fetch mode within an extended class of Zend_Db_Table_Abstract. The following does not work:

<?php
class Foo extends Zend_Db_Table_Abstract
{ยท
  function bar()
   {
     return $this->fetchAll(Zend_Db::FETCH_NUM);
   }
}

Anybody have an idea how to do it properly?? Thanks!

mdthh
  • 1,248
  • 1
  • 13
  • 22

2 Answers2

2

I don't think Zend_Db_Table is the right thing to use if you just want to fetch data by column number, since Zend_Db_Table's fetchAll() method will always want to return a rowset of, in this case, Foo rows. And the rows use the column names as object properties.

If you really need to fetch with numbered indexes, try using the DB Adapter instead of the DB Table instead:

function bar() {
    $dbAdapter = $this->getAdapter();
    $dbAdapter->setFetchMode(Zend_Db::FETCH_NUM);
    return $dbAdapter->fetchAll("SELECT * FROM " . $this->_name);
}
Konr Ness
  • 2,083
  • 1
  • 14
  • 8
2

I hope this could help you.

<?php
class Langs extends Zend_Db_Table_Abstract
{
    protected $_name = 'langs';
    protected $_primary = 'id';


    public function getLangs() {
        $query = "SELECT lang_short "
               . "FROM $this->_name "
               . "ORDER BY $this->_primary";

        return $this->_db->fetchAll($query, null, Zend_Db::FETCH_OBJ);
    }
}
R Picheta
  • 630
  • 9
  • 16