Home > PHP Framework > YII > How to debug sql in yii

How to debug sql in yii

王林
Release: 2020-06-12 18:28:26
forward
2994 people have browsed it

How to debug sql in yii

Yii debugging SQL mainly has the following methods:

1. The system comes with debugging:

First index.php turns on the debugging mode:

// remove the following lines when in production mode 
defined('YII_DEBUG') or define('YII_DEBUG',true); 
// specify how many levels of call stack should be shown in each log message 
defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL',3); 
//app use time 
//defined('YII_BEGIN_TIME') or define('YII_BEGIN_TIME',microtime(true));
Copy after login

main.php page:

'errorHandler'=>array( 
  // use 'site/error' action to display errors 
  'errorAction'=>'site/error', 
), 
'log'=>array( 
  'class'=>'CLogRouter', 
  'routes'=>array( 
    array( 
      'class'=>'CFileLogRoute', 
      'levels'=>'error, warning', 
    ), 
    // 下面显示页面日志 
    array( 
      'class'=>'CWebLogRoute', 
      'levels'=>'trace',   //级别为trace 
      'categories'=>'system.db.*' //只显示关于数据库信息,包括数据库连接,数据库执行语句 
    ),    
  ), 
),
Copy after login

The larger the number of YII_TRACE_LEVEL, the clearer the information

2. Use debugging tools to debug:

yii-debug-toolbar Unzip the package and put it in extensions, then add

'log'=>array( 
   'class'=>'CLogRouter', 
   'routes'=>array( 
     array( 
       'class'=>'ext.yii-debug-toolbar.YiiDebugToolbarRoute', 
       'ipFilters'=>array('127.0.0.1','192.168.1.215'), 
     ), 
   ), 
 ),
Copy after login

at the end of the configuration file main.php. If it does not appear, add two attributes

'enableProfiling'=>true, 
'enableParamLogging'=>true,
Copy after login

in the db under 'components' and then If there are plug-ins for other debugging tools, conflicts may occur and the sql statement will not appear. Just comment out that code.

Recommended tutorial: yii

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

Related labels:
source:jb51.net
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