Yii view (output) The SQL statement executed by the current page

Source: Internet
Author: User
Tags yii

The method of viewing all SQL statements executed by the current page under the YII framework, mainly by configuring related files to achieve the purpose of debugging SQL, as follows:

(1) Modify index.php Open Debug mode

Add the following two lines of code (if not present) in the index.php file:

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

(2) Modify the configuration file main.php

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

View Code Printing
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 ),

OK, after the above settings, refresh the page, you can go to the D:\phpStudy\WWW\phpernote\com\tmpfile\log_db directory to find the generated SQL record file. The output log format is as follows:

[Time]-[level]-[category]-[content]

2015/04/17 10:30:51 [Trace] [System.db.CDbCommand] querying sql:select * from ' phpernote_article ' ORDER by id desc LIMIT 15

Yii view (output) The SQL statement executed by the current page

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.