标签:
打印ar或者query的原始sql:
$query = (new \yii\db\Query())
->select([‘a.username‘,‘b.item_name‘])
->from([‘a‘ => ‘user‘])
->leftJoin([‘b‘ => ‘auth_assignment‘], ‘a.id = b.user_id‘)
->where([‘a.username‘ => ‘admin‘])
->andWhere([‘between‘, ‘a.created_at‘, 1467626063, 1467626064])
->limit(10);
// get the AR raw sql in YII2
$commandQuery = clone $query;
echo $commandQuery->createCommand()->getRawSql();
$users = $query->all();
注意$query不能带all,find()
返回值类型是 yii\db\ActiveQuery
, find()->all()
返回的就是数组了。
标签:
原文地址:http://www.cnblogs.com/huanxiyun/p/5699081.html