Zend Framework 2: subqueries

后端 未结 2 1526
别那么骄傲
别那么骄傲 2021-01-01 01:21

ZF2 recently updated to version 2.1.4 with a database API has changed http://framework.zend.com/security/advisory/ZF2013-03

Now the code that I used for a subquery w

相关标签:
2条回答
  • 2021-01-01 01:47

    Please try this.

    $sql = new Sql($this->_adapter);
    $mainSelect = $sql->select()->from('mt1');
    $subQry = $sql->select()
            ->from('md_type')
            ->columns(array('orderCount' => new \Zend\Db\Sql\Expression('COUNT(md_type.parent_id)')))
            ->where('mt2.parent_id = mt1.id');
    $mainSelect->columns(
            array(
                'id', 
                'total' => new \Zend\Db\Sql\Expression('?', array($subQry)),
            )
    );
    
    $statement = $sql->prepareStatementForSqlObject($mainSelect);
    $comments = $statement->execute();
    $resultSet = new ResultSet();
    $resultSet->initialize($comments);
    
    return $resultSet->toArray();
    

    Reference: ZF2 - subqueries

    0 讨论(0)
  • 2021-01-01 01:49

    I ran into this same issue trying to run subqueries with exists. I wrote up a blogpost with code examples that walk you through how to set it up. http://aronkerr.blogspot.com/2013/08/zf2-sql-exists-sub-query-using-zf2.html?m=1

    0 讨论(0)
提交回复
热议问题