yii打印sql语句

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语句不出来,把那段代码注掉即可。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值