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

How to print sql statement in yii2?

coldplay.xixi
Release: 2020-07-21 15:35:13
Original
5260 people have browsed it

yii2 How to print sql statements: You can execute the statement in the controller, the code is [$model->find()->createCommand()->getRawSql();], click on the web page You can see the sql statement in the log at the bottom.

How to print sql statement in yii2?

yii2 method of printing sql statement:

If you want to print this Sql, you can use

$model->find()->createCommand()->getRawSql();
Copy after login

You can see it in the debugger at the bottom of the web page. Click on the log to see the sql language you executed (that is, the sql statement for consecutive operations);
For example, in the controller, you execute

 $query= ReleaseForm::find()->where(['type'=>1])->all();
Copy after login

Note: The source code is these:

$query=  ReleaseForm::find()->where(['type'=>1]);
$pagination = new Pagination([
    'defaultPageSize' => 5,
    'totalCount' => $query->count(),
]);
        
$property_data= $query
    ->offset($pagination->offset)
    ->limit($pagination->limit)
    ->all();
Copy after login

In the web page, you can click on the log at the bottom to see:


10 21: 01:36.667 info yii\db\Command::query SELECT COUNT(*) FROM `releases` WHERE `type`=1
E:\web\Apache24\htdocs\basic\controllers\PropertyController.php (14)
11 21:01:36.667 info yii\db\Connection::open Opening DB connection: mysql:host=localhost;dbname=xunwu
E:\web\Apache24\htdocs\basic\controllers\PropertyController.php ( 14)
12 21:01:36.669 info yii\db\Command::query SELECT * FROM `releases` WHERE `type`=1 LIMIT 5
E:\web\Apache24\htdocs\basic\controllers\ PropertyController.php (20)
13 21:01:36.670 info yii\db\Command::query SHOW FULL COLUMNS FROM `releases`
E:\web\Apache24\htdocs\basic\controllers\PropertyController.php (20)
14 21:01:36.674 info yii\db\Command::query SHOW CREATE TABLE `releases`

This way you will know what sql statement you executed

Related learning recommendations: yii tutorial

The above is the detailed content of How to print sql statement in yii2?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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
Latest Issues
yii2 error connecting to mongodb3.2.4
From 1970-01-01 08:00:00
0
0
0
How to use mongodb to do rbac in yii2
From 1970-01-01 08:00:00
0
0
0
php - yii2-ueditor-widget
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template