将Zend_Db_Select的输出更改为Zend_Db_Table_Rowset

时间:2010-06-23 19:04:38

标签: zend-framework zend-db-table

我在扩展Zend_Db_Table_Abstract的类中包含以下代码:

public function fetchByFriends($id) {
    /*
     * SELECT * FROM list 
     * INNER JOIN friendship ON 
     * list.user_id = friendship.friend_id
     * WHERE friendship.user_id = ?
     */

    $select = $this->select()
                   ->from("list")
                   ->join("friendship", "list.user_id = friendship.friend_id")
                   ->where("friendship.user_id = ?", $id);
    $select->setIntegrityCheck(false); // allows joins within a DbTable

    $stmt = $select->query();
    return $this->fetchAll($stmt);
}

虽然查询工作正常,但返回的数据是一个数组。有没有办法重构这个,以便fetchAll将其作为Zend_Db_Table_Rowset而不是数组返回?

1 个答案:

答案 0 :(得分:0)

我的研究很差。我在Zend的参考手册中找到了答案:

<强> Advanced usage

  

示例#27使用查找表优化fetchAll()的结果

$table = new Bugs();

// retrieve with from part set, important when joining
$select = $table->select(Zend_Db_Table::SELECT_WITH_FROM_PART);
$select->setIntegrityCheck(false)
       ->where('bug_status = ?', 'NEW')
       ->join('accounts', 'accounts.account_name =
     

bugs.reported_by')               - &gt; where('accounts.account_name =?','Bob');

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