douxian4323 2012-03-25 13:59
浏览 81
已采纳

使用Zend_Db_Table_Abstract限制查询返回列

How do I limit a query to specific columns while using Zend_Db_Table_Abstract?

(getDbTable() below returns a Zend_Db_Table_Abstract object)

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

I only need the id column returned but the entire row is returned. Thanks for any help!

  • 写回答

2条回答 默认 最新

  • dragam0217 2012-03-25 14:36
    关注

    As stated in the docs :

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

    So, for you :

    $resultSet = $this->getDbTable()->fetchAll(
           $this->getDbTable()->select()
            ->from($this->getDbTable(), array('id'))
            ->where('forgienKey = \'' . $forgienKey . '\'')
            ->order("'id' ASC")
    );
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?