How to select particular field of db table from model

zend-framework

Suppose that i have a table 't' with fields 'id' int 11, 'name' varchar 50, and 'description' text. if the text is very large, and i am querying the database with 'description' and without 'description', will there be any difference?

and how to select only 'id' and 'name' in the Model that extends Zend_Db_Table_Abstract class?

Best Answer

In term of perfomances I can't really help, but it should not make a big difference.

For your question about how to select fields in a query look at the following

class Model_DbTable_T extends Zend_Db_Table_Abstract{
    protected $_name = 't'; // this line is optionnal if your table has the same name as the class

    public function fetchSomeFields(){
        $query = $this->select()
                      ->from($this,
                             array('id')); // you could also include the 'as' statement in the field name to make it look like 'id as otherName'
        return $this->fetchAll($query);
    }
}
Related Topic