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