I want to make mysql query to get the highest 5 values in a column from a table,
so the query is :
'SELECT * FROM files ORDER BY `uploadDate` DESC LIMIT 5'
how to run this query and save its value in a variable?
I prefer to use findAll() method with these options if it is possible.
解决方案
There are several ways to achieve this, but if you prefer the query builder way
$results = Yii::app()->db->createCommand()->
select('id, filename, uploadDate')->
from('files')->
order('uploadDate DESC')->
limit(5)->
queryAll();
var_dump($results);