自学内容网 自学内容网

yii2打印最终SQL

yii2打印最终SQL
$query = User::find()
  ->select('id,username,mobile')
  ->where(['in','id',[1,5,8,9])
  ->order('id DESC');
$commandQuery = clone $query;
echo $commandQuery->createCommand()->getRawSql();
$users = $query->all();

输出:
select id,username,mobile form user where id in(1,5,8,9) order by id DESC;

不能带 all(). find() 它的
返回值类型是 yii\db\ActiveQuery,
而find()->all() 返回的就是数组了 所以写在all 之前打印即为字符串SQL语句

原文地址:https://blog.csdn.net/qq_16659821/article/details/136044761

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!