Hello i try generate a query in Zend 2 just like this
select top 10 * from mensaje where idUsuario = 11 order by fechaAltaMensaje DESC
i try use this
$select = $sql->select();
$select->from('mensaje');
$select->where('idUsuario = '.$idUser.' order by fechaAltaMensaje DESC');
$select->limit(5);
but don't work
You are missing some details in your code in order for it to work,
please see below.
Please read the tutorials below and you will get the full picture
Examples
Examples 2
The
limit
function only applies to platforms that support it. To achieve what you're after in SQL you need to use thequantifier
function.Also -
where
accepts an array ofcolumn => value
pairs.And there is an
order
function that accepts a column name and direction:I am not pleased with Zends implementation of the sql abstraction layer, when you need to use two different functions to write SQL that is not cross platform to do simple things like
limit
ortop
. That's just my two pence.