Order by in Zend Framework

Came across a nice “gotcha” using Zend _Db in Zend Framework 1 if you’re being sloppy like I was. When you’re ordering by multiple columns, always make sure to use an array.


$select->order('col1', 'col2', 'col3');


$select->order(array('col1', 'col2', 'col3'));

If you take a look at the order function in Zend_Db_Select, it takes a mixed parameter (string or array) and operates on that. If you’re not seeing PHP warnings, you won’t notice that the parameters ‘col2’ and ‘col3’ are being ignored.