php - preparing ZF2 query for a particular mysql query -
php - preparing ZF2 query for a particular mysql query -
how can prepare zf2 query bellow mysql query
select (select category_name categories category_id = c.parent_id) category_name ebook e bring together ebook_categories ec on ec.ebook_id = e.ebook_id bring together categories c on c.category_id = ec.category_id e.is_active = 1 grouping category_name
you can using tablegateway in zf2. example:
public function fetchallwithlikes( $user_id ) { $adapter = $this->getadapter(); $resultset = $this->select( function( select $select ) utilize ( $user_id, $adapter ) { $sub1 = new select( 'likes' ); $sub1->columns( array( 'total' => new expression('count(*)') ) ) ->where( array( 'id' => new expression( 'song_id' ) ) ); $sub2 = new select( 'likes' ); $sub2->columns( array( 'total' => new expression('count(*)') ) ) ->where( array( 'id' => new expression( 'song_id' ) ) ) ->where( array( 'user_id' => $user_id ) ); $select->columns( array( 'id', 'title', 'ytlink', 'total_likes' => new \zend\db\sql\expression( '?', array( $sub1 ) ), 'your_likes' => new \zend\db\sql\expression( '?', array( $sub2 ) ), ) ); var_dump( $select->getsqlstring( $adapter->getplatform() ) ); }); homecoming $resultset->toarray();
}
php zend-framework zend-framework2
Comments
Post a Comment