how to run a mysql query in yii
11,704
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);
Read this documentation for more detail : http://www.yiiframework.com/doc/guide/1.1/en/database.query-builder
Author by
Mohammad
<?php $this->mode(EXCITED_TO_PROGRAM); $this->SoReadyToHelp(true); ?> NEXT GOAL? to be the first in this list: Top stackoverflow users in Lebanon
Updated on June 04, 2022Comments
-
Mohammad almost 2 years
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.