Yii調試SQL主要有以下方法:
一、系統自帶調試:
首先index.php開啟調試模式:
// 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頁面:
'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.*' //只顯示關於數據庫信息,包括數據庫連接,數據庫執行語句
),
),
),
YII_TRACE_LEVEL的數字越大,信息越清楚
二、使用調試工具調試:
yii-debug-toolbar把包解壓後 放到extensions裡邊 然後在配置文件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'),
),
),
),
沒有出現的話加上在'components'下的db裡加上兩個屬性,
'enableProfiling'=>true, 'enableParamLogging'=>true,
然後如果有其他調試工具的插件的話,可能會出現沖突導致sql語句不出來,把那段代碼注掉即可。