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語句不出來,把那段代碼注掉即可。