i want to see my query as a string so that i can change my query instantly
i want to see my query as a string so that i can change my query instantly
You’d need to override CActiveRecord::query to get access to the command before it is executed.
But if you explain your goals we may be able to help you better.
It will be REALLY hard to modify final SQL query. The query is generated deep in CActiveRecord and CActiveFinder with help of CCommandBuilder just before fetching data and because of AR relation model this is rather complicated task. You should rather properly use criteria.
Thanks for you quick replys ,
i am creating query like this
$model->attributes=$_POST['Test'];
$word = $model->attributes['word'];
$result = Yii::app()->db->createCommand()
->select('word,meaning,example,pronouns')
->from('tbl_hindi')
->where('meaning=:word', array(':word'=>$word))
->queryRow();
i just want to see the query just like
select word,meaning,example,pronouns from hindi
where word = demo ;
on my page .
aaa, I thought you want to see/modify query generated with ActiveRecord. When using just CDbCommand - you may use getText(), or you can also add profile routing and enable sql profiling on db connections - this way you will see every (even those generated with AR) sql executed in report below your page.
'db'=>array(
.....
'enableParamLogging'=>true,
'enableProfiling'=>true,
),
'log'=>array(
...
'routes'=>array(
...
array(
'class'=>'CProfileLogRoute',
'report'=>'summary',
),
),
),
Thanks redguy,
its really wonder full and thanks again for your help