繁体   English   中英

使用Zend_Db_Table_Abstract限制查询返回列

[英]Limit a query return columns with Zend_Db_Table_Abstract

使用Zend_Db_Table_Abstract时,如何将查询限制为特定列?

(下面的getDbTable()返回一个Zend_Db_Table_Abstract对象)

$resultSet = $this->getDbTable()->fetchAll(
       $this->getDbTable()->select()
        ->where('forgienKey = \'' . $forgienKey . '\'')
        ->order("'id' ASC")
    );

我只需要返回id列,但返回整行。 谢谢你的帮助!

文档所述

$select = $table->select();
$select->from($table, array('bug_id', 'bug_description'))
       ->where('bug_status = ?', 'NEW');

$rows = $table->fetchAll($select);

所以,对你来说:

$resultSet = $this->getDbTable()->fetchAll(
       $this->getDbTable()->select()
        ->from($this->getDbTable(), array('id'))
        ->where('forgienKey = \'' . $forgienKey . '\'')
        ->order("'id' ASC")
);

请试试这个

$resultSet = $this->getDbTable()->fetchAll(
       $this->getDbTable()->select()
        ->columns('id')
        ->where('forgienKey = \'' . $forgienKey . '\'')
        ->order("'id' ASC")
);

编辑

检查链接

http://framework.zend.com/manual/en/zend.db.select.html

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM