【问题标题】:How to select particular field of db table from model?如何从模型中选择数据库表的特定字段?
【发布时间】:2013-03-12 20:44:36
【问题描述】:

假设我有一个表 't' 字段 'id' int 11、'name' varchar 50 和 'description' 文本。如果文本很大,我用'description'和没有'description'查询数据库,会有什么区别吗?

以及如何在扩展 Zend_Db_Table_Abstract 类的模型中只选择“id”和“name”?

【问题讨论】:

    标签: zend-framework


    【解决方案1】:

    就性能而言,我真的帮不上什么忙,但应该不会有太大的不同。

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-12-03
      • 1970-01-01
      • 2023-02-21
      • 1970-01-01
      • 2016-12-10
      • 1970-01-01
      • 2016-03-25
      相关资源
      最近更新 更多