0

我在扩展的类中有以下代码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,而不是数组?

4

1 回答 1

0

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

高级用法

Example #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') ->where('accounts.account_name = ?', 'Bob');

$rows = $table->fetchAll($select);
于 2010-06-23T19:12:08.583 回答