createCommand()->getRawSql();" to print sql statements. The "$query->createCommand()->getRawSql()" statement can obtain the currently executed sql statement."/> createCommand()->getRawSql();" to print sql statements. The "$query->createCommand()->getRawSql()" statement can obtain the currently executed sql statement.">
Home >PHP Framework >YII >How to print sql statement in yii2.0
Yii 2.0 provides 2 data operation methods, one is data model [models] and the other is [\yii\db\Query()]. Which one to use, see Personal preferences.
The examples of printing sql statements in models mode are as follows:
$query = User::find()->where(['id'=>[1,2,3,4])->select(['username']) echo $query->createCommand()->getRawSql();
\yii\db\Query() The examples of printing sql statements in mode are as follows:
$query = (new \yii\db\Query())->select('id')->from('channel')->where('id = 1'); echo $query->createCommand()->getRawSql();
Recommended learning: yii frame
The above is the detailed content of How to print sql statement in yii2.0. For more information, please follow other related articles on the PHP Chinese website!