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 output sql statement in Yii?
Yii is a high-performance PHP5 web application development framework for developing large-scale web applications. A simple command line tool yiic can quickly create a web application code framework. Developers can add business logic based on the generated code framework to quickly complete application development.
And yii2.0 is the 2.0 version of the Yii framework. Because the Yii2.0 version framework is completely rewritten, there are quite a few differences between the 1.1 and 2.0 versions. [Recommended learning: yii framework]
Yii 2.0 provides 2 data operation methods, one is data model [models], and the other is [\yii\db\Query()] , which one to use depends on personal preference.
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();
For more related knowledge, please pay attention PHP中文网! !
The above is the detailed content of How to output sql statement in Yii?. For more information, please follow other related articles on the PHP Chinese website!