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

How to print sql statement in yii2.0

尚
Original
2019-12-24 14:04:124229browse

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn