hemachandra
(Hemachandra Gaaja)
1
Hi All,
i am able to get results from my db, but when i am passing "ORDER BY id DESC, LIMIT 1" as params, the query is not giving results based on ORDER.
$work = Work::getData($fields, array('AND', 'rolw=10', array('id' => SORT_DESC) ); // i want to pass order by id DESC and limit,10 as array
following is my function
public function getData($fields, $where, $params = array()){
return Yii::app()->db->createCommand()
->select($fields)
->from(self::TABLE . ' as t')
->where($where, $params)
->queryAll();
}
i am not sure why params are not working!!!. Is there anything i am missing??
amir.duran
(Amir Duran)
2
I think you are not calling your function properly, because your $params array is empty (you are not passing 3rd argument).
You want to order elements but you are not calling order method!
[size="2"]Use something like this: [/size]
public static function getData($fields, $where, $params = array(), $order, $limit){
$query = Yii::app()->db->createCommand()->select($fields)->from(self::TABLE . ' as t');
$query->where($where, $params);
if(isset($order))
$query->order($order);
if(isset($limit)){
$query->limit($limit);
}
return $query->queryAll();
}
Then call it like:
Model::getData($fields, 'id=:id', array(':id'=>15), 'column1, column2', 10)