如何从模型中选择db表的特定字段?

时间:2011-01-04 18:43:02

标签: zend-framework

假设我有一个表't',其字段'id'int 11,'name'varchar 50和'description'文本。如果文本非常大,我用“描述”查询数据库而没有“描述”,那会有什么不同吗?

以及如何在扩展Zend_Db_Table_Abstract类的模型中仅选择'id'和'name'?

1 个答案:

答案 0 :(得分:4)

就性能而言,我无法提供帮助,但它不应该有很大的不同。

有关如何在查询中选择字段的问题,请查看以下内容

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);
    }
}