Home > PHP Framework > YII > body text

How to output sql statement in Yii?

青灯夜游
Release: 2020-05-11 18:31:12
Original
2557 people have browsed it

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();
Copy after login

\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();
Copy after login

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!

Related labels:
yii
source:php.cn
Statement of this Website
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 [email protected]
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!