Common Methods of Debugging SQL with Yii

  • 2021-07-07 06:44:32
  • OfStack

Yii debugging SQL mainly has the following methods:

1. The system comes with debugging:

First, index. php turns on debug 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', 
    ), 
    //  The page log is displayed below  
    array( 
      'class'=>'CWebLogRoute', 
      'levels'=>'trace',   // Level is trace 
      'categories'=>'system.db.*' // Show only information about the database , Include database connections , Database execution statement  
    ),    
  ), 
),

The larger the number of YII_TRACE_LEVEL, the clearer the information

2. Use debugging tools to debug:

yii-debug-toolbar Extract the package and put it in extensions and add it at the end of the configuration file main. php


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

If it doesn't appear, add two attributes in db under 'components'.


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

Then, if there are plug-ins of other debugging tools, there may be conflicts that lead to the sql statement not coming out, so just note out that code.


Related articles: