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  >  Article  >  PHP Framework  >  How to output sql statement in Yii?

How to output sql statement in Yii?

青灯夜游
青灯夜游Original
2020-04-20 17:36:472766browse

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.

How to output sql statement in Yii?

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!

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