问题
I want to show the query which is generated when we call the function $model->save() of a model. I did not find any way to do it. If anyone knows please reply.
Thanks
回答1:
Change your 'db' component in your config file -
'db'=>array(
…
'enableProfiling'=>true,
'enableParamLogging' => true,
),
Then check wherever you are logging everything. If file, it will be application.log file. Else on the page itself. To enable logging in file -
'log'=>array(
'class'=>'CLogRouter',
'routes'=>array(
array(
'class'=>'CWebLogRoute',
'levels'=>'trace, info, error, warning',
),
array(
'class'=>'CFileLogRoute',
// 'categories' => 'system.db.*',
'levels'=>'trace, info, error, warning',
),
),
来源:https://stackoverflow.com/questions/9598179/how-to-show-insert-query-generated-through-model-save-function