用原生态的写法好像太low了,比如createCommand("select * from note limit 10")->queryRow()这种。
用ActiveRecord有时候又有点麻烦而没必要,那么可以用Class yii\db\Query里面的方法来实现。具体的用法:
$query = new yii\db\Query;
$res = $query->select('*')->from('article')->where(['cat'=>2,'type'=>3])->orderBy(['id'=>'DESC'])->limit(10);
要是连表查询的话就是这样:
$res = $query->select(['a.*', 'c.name'])->from('article as a')->leftJoin('category as c', 'a.cid=c.id')->where(['cat'=>2])->limit(10);