This article mainly introduces the common methods for Yii to debug SQL. if you need it, you can refer to the following methods for Yii to debug SQL:
1. built-in system debugging:
First, enable the index. php 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 ('class' => 'cfilelogroute ', 'levels' => 'Error, warning',), // The page log array ('class' => 'cweblogroute ', 'levels' => 'track ', // trace 'categories '=> 'system. db. * '// only displays information about the database, including database connection and database execution statements ),),),
The greater the number of YII_TRACE_LEVEL, the clearer the information.
II. use debugging tools for debugging:
Yii-debug-toolbar decompress the package, put it in extensions, and add it to 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 does not appear, add two attributes to the database under 'Components,
'enableProfiling'=>true, 'enableParamLogging'=>true,
If there are plug-ins of other debugging tools, conflicts may occur, resulting in SQL statements not coming out. just note the code.