Yii2 打印sql语句


Yii2 打印sql语句


正文

在yii2程序开发中,有时我们需要知道执行的sql语句具体是什么,怎么查看呢?

下面写个例子:

$data = CasePlan::find()->alias('c')->select('c.*');
echo $data->createCommand()->getRawSql();  
// SELECT `c`.* FROM `case_plan` `c` 
$data = User::find()->select('*')->where(['or', ['like', 'nick', $content], ['like','mobile', $content]]);
echo $data->createCommand()->getRawSql();    
// SELECT * FROM `user` WHERE (`nick` LIKE '%1%') OR (`mobile` LIKE '%1%')






参考资料

http://www.yiichina.com/question/616


返回