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

后端 未结 5 2054
你的背包
你的背包 2021-02-08 15:51

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 16:06

    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));
    

提交回复
热议问题