Home > PHP Framework > YII > How to print sql statement in yii2.0

How to print sql statement in yii2.0

Release: 2019-12-24 14:04:12
Original
4280 people have browsed it

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();
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

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!

Related labels:
sql
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 admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template