Home  >  Article  >  PHP Framework  >  How to view the SQL statements executed by the current page in Yii

How to view the SQL statements executed by the current page in Yii

王林
王林Original
2020-02-27 11:52:293231browse

How to view the SQL statements executed by the current page in Yii

This can be achieved by configuring relevant files. The specific method is as follows:

(1) Modify index.php and enable debugging mode

In index.php Add the following two lines of code to the file (if it does not exist):

1    //开启调试模式    
2    defined('YII_DEBUG') or define('YII_DEBUG',true);    
3    //设置日志记录级别,YII_TRACE_LEVEL的数字越大,信息越清楚    
4    defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL',3);

(Recommended tutorial: yii framework)

(2) Modify the configuration file main.php

Add the following array under components - log - routes in config/main.php:

1    array(     
2        'class'=>'CFileLogRoute',//文件记录日志的形式    
3        'levels'=>'trace',//日志记录级别    
4        'categories'=>'system.db.*',//只显示关于数据库信息,包括数据库连接,数据库执行语句    
5        'logFile' => 'app_'.date('Y-m-d').'.log',//日志保存文件名    
6        'logPath'=>'D:\phpStudy\WWW\phpernote\com\tmpfile\log_db',//日志保存路径    
7    ),

After the above settings, refresh the page, you can go to D:\phpStudy\WWW\phpernote\ Look for the generated sql record file in the com\tmpfile\log_db directory.

For more programming related content, please pay attention to the Programming Introduction column on the php Chinese website!

The above is the detailed content of How to view the SQL statements executed by the current page 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