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

后端 未结 5 1371
情深已故
情深已故 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:30

    After long search I handel my SQL Query in ZF2 that way

     $sql = new \Zend\Db\Sql\Sql($this->tableGateway->getAdapter());
        $select = $sql->select();
        $select->from('table'); 
        $select->columns(array('*'));
        $select->join("join table", "table.id = join table.id", array("*"), "left");
        $statement = $sql->prepareStatementForSqlObject($select);
        $results = $statement->execute();
        return iterator_to_array($results));
    

    The trick is the PHP function iterator_to_array

提交回复
热议问题