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

后端 未结 5 1322
情深已故
情深已故 2021-02-08 15:36

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:10

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

提交回复
热议问题