简体   繁体   中英

How to log query being executed by Yii CDbCriteria

有什么方法可以查看CDbCriteria正在执行的查询吗?

I personally use this in my config file protected/config/main.php

// SQL Commands
array(
  'class'=>'CFileLogRoute',
    'maxFileSize' => 30720,
    'maxLogFiles' => 10,
    'rotateByCopy' => true,
  'levels'=>'trace,info,error,warning',
  'logFile'=>'sql.log',
  'categories'=>'system.db.CDbCommand'
),

Reference: http://www.yiiframework.com/doc/guide/1.1/en/topics.logging

Notice categories index: http://www.yiiframework.com/doc/api/1.1/CLogRoute#categories-detail

array of categories, or string list separated by comma or space. Defaults to empty array, meaning all categories.

CDbCriteria doesn't execute queries itself, it is passed to other classes like CActiveDataProvider or methods like find() , etc which calls CDbCommand in the end. So we log only that category.

I am not that good with terminology, hope you got it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM