Question about simple query in ZF2

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Question about simple query in ZF2

Jigal Sanders
Hello and good morning to you all,

I am following the qickstart tutorial from Rob Allen in the manual.
I am trying to change some things. One of the things I am trying to do is
to get a query like this:

"SELECT max(id) FROM Albums";

I tried things like

$this->select();
$this->columns(array('id' => 'MAX(id)'));

Apparently this is not the way to do it.
I probablly need some expression object or so.

Can anyone tell me how to solve this?


Thanks


J. Sanders
Reply | Threaded
Open this post in threaded view
|

Re: Question about simple query in ZF2

samsonasik
This post has NOT been accepted by the mailing list yet.
use Zend\Db\Sql\Select;

$resultSet = $this->select(function (Select $select){
    $select->columns(array( new \Zend\Db\Sql\Expression('max(id) as id')));
});