如何获取 YII2 AR 执行的 SQL 语句,直接用程序输出,而不是通过日志去查看

2016-8-18 liyangweb.com 李杨 PHP

$query = User::find()
  ->where(['id'=>[1,2,3,4])
  ->select(['username'])
// get the AR raw sql in YII2
$commandQuery = clone $query;
echo $commandQuery->createCommand()->getRawSql();
$users = $query->all();

转自:https://gist.github.com/dcb9/e5fd296ba4bca16bf98c

标签: yii2

评论:

大鹏
2016-08-20 12:02
最近更新博客有些频繁啊!
liyangweb.com 李杨
2016-08-23 23:17
@大鹏:发现不错的东西,就顺便搬过来了~~~

发表评论:

Powered by emlog 冀ICP备13011830号-1