Zend Framework 2 Db\Adapter\Adapter query resultset like ZF1

前端 未结 5 1114
滥情空心
滥情空心 2021-02-08 18:38

Just need a hand understanding some simple database queries in ZF2. In ZF1 I have simple methods like this:

public function recordset()
{
// listing of all reco         


        
5条回答
  •  忘了有多久
    2021-02-08 19:01

    From http://framework.zend.com/manual/2.0/en/modules/zend.db.result-set.html:

    Zend\Db\ResultSet is a sub-component of Zend\Db for abstracting the iteration of rowset producing queries.

    So you can do the following:

    $statement = $db -> query($sql);
    
    /** @var $results Zend\Db\ResultSet\ResultSet */
    $results = $statement -> execute();
    
    $returnArray = array();
    // iterate through the rows
    foreach ($results as $result) {
        $returnArray[] = $result;
    }
    

    Now you can send it to the view:

    return new ViewModel(array('results' => $returnArray));
    

提交回复
热议问题