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

How to debug sql in yii

王林
王林forward
2020-06-12 18:28:262933browse

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

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.*' //只显示关于数据库信息,包括数据库连接,数据库执行语句 
    ),    
  ), 
),

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'), 
     ), 
   ), 
 ),

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

'enableProfiling'=>true, 
'enableParamLogging'=>true,

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!

Statement:
This article is reproduced at:jb51.net. If there is any infringement, please contact admin@php.cn delete