我用过这种方式
$blog = Yii::app()->db
->createCommand()
->from('blog')
->Where('status=:status',array(':status'=>'Active'))
->limit(array('0,5'))
->order(array('RAND()'))
->queryAll();
但它无法正常工作..
答案 0 :(得分:1)
RAND()
必须在CDbExpression
$blog = Yii::app()->db
->createCommand()
->from('blog')
->Where('status=:status',array(':status'=>'Active'))
->limit(array('0,5'))
->order(new CDbExpression("RAND()"))
->queryAll();