This article mainly introduces the common methods of debugging SQL in Yii. Friends who need it can refer to it
The main methods of debugging SQL in Yii are as follows:
1. The system comes with it Debugging:
First index.php turns on 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 into 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 it under 'components'. Add two attributes to the db,
'enableProfiling'=>true, 'enableParamLogging'=>true,
Then if there are plug-ins for other debugging tools, conflicts may occur and the sql statement will not come out. Change that code Just note it out.
The above is the entire content of this article. I hope it will be helpful to everyone's study. For more related content, please pay attention to the PHP Chinese website!
Related recommendations:
How to implement Yii clean cache
##About the operation of connecting ZendFramework2 to the database
Yii2 framework implements analysis of common database operations
The above is the detailed content of How to debug SQL using Yii. For more information, please follow other related articles on the PHP Chinese website!