SQL statement

Hi All,

sorry for the stupid question. I’m approching with yy only by yesterday

I have a simple question 4 you.

If I need to create a sql statement(not using AR)

ex: $sql="INSERT INTO tbl_user (username, email) VALUES(:username,:email)";


Should I put this command on UserController? as a method or other?

Sorry for the stupid question

All sql code should go to a model. Moreover, you can use CDbCommandBuilder.createInsertCommand() for this purpose.

It depends on when this command is supposed to run.

If it has to run when a particular url is requested, you should place in the action/controller where the command is supposed to run.

Why you don’t want to use active record? If you are approaching to Yii only yesterday, I advice you to use the most possible the framework instruments.

If you want to approach to a framework with your own programming style, you risk that the framework will be an obstacle instead of an help.

Better to do:

$user = new TblUser;