How can I get the rawSql executed after a $model->save()??
Thank you so much.
My code return null
$model->save();
$sql = $model->getDb()->createCommand()->getRawSql();
echo ($sql);
How can I get the rawSql executed after a $model->save()??
Thank you so much.
My code return null
$model->save();
$sql = $model->getDb()->createCommand()->getRawSql();
echo ($sql);
Turn on logging, check what’s there.
Thanks samdark. I’ll take a look and try it.
You are running no SQL all all. Try
$sql = MyModel::find()->createCommand()->getRawSql();
Thanks Stefano…it works
But that shows me “SELECT * FROM table”
and what I hope to see is
“UPDATE table SET…”
You can see sql if you use the debugger.
I think you can get sql with parameters if you use profiling.
https://www.yiiframework.com/doc/guide/2.0/en/runtime-logging#performance-profiling
I think you misunderstand what is the use of that method. It shows you the raw SQL instead of actually running a command. But you need to build up that command first.
Thanks for your answer.
It is possible that I have not understood the use or it may not be the solution I am looking for.
But my initial question is clear. Is it possible to know what is the SQL statement that YII creates to execute the save() method of a model?
@tri have pointed you to an answer to that question. And Yes, for that problem rawSql
is not the solution you are looking for