database problem,help!



$this->status=0;


$this->save();


I do this, but return error as follows:

CDbCommand failed to execute the SQL statement: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 1

then i change to:

$this->dbConnection->createCommand("UPDATE users SET status = 0 WHERE users.id = {$this->id} LIMIT 1")->execute();

everything is OK!

but both of them can change the data in mysql right。。the first way return error,why?

You might want to post the generated SQL found in the "runtime/application.log" along with this Exception.

With that we could analyze if this indicates a bug in Query-generation.

Quote

You might want to post the generated SQL found in the "runtime/application.log" along with this Exception.

With that we could analyze if this indicates a bug in Query-generation.

Thank you for your help  :)

This is the info in my application.log

 INSERT INTO users_has_roles (users_id, roles_id) VALUES(4, )

it seems that I had know the reason. It lost a parm.

'roles' => array(self::MANY_MANY, 'Roles', 'users_has_roles(users_id, roles_id)'),

I only add this to my relations funtion, but I can't understant why the yii want to INSERT a record to the users_has_roles table! And how can I avoid this?

Did you write afterSave() in your main model class? No, Yii won’t automatically insert a record.