ActiveRecord deleteAll

Hello,

I am facing strange behavior when I try to delete a record in a table. my code is the following :




		Account::model()->deleteAll(array(

			'condition' => "`active` = ':active' AND (`name` LIKE ':name' OR `email` LIKE ':email')",

			'params' => array(':active' => self::INACTIVE, ':name' => $name, ':email' => $email ),

		));



  1. There is a record in accounts table that matches the condition, but it is not being deleted, even no errors has been thrown!

I have sql queries logging enabled, and I tried to see the executed query, and it looks like the following :




2010/04/09 17:36:06 [trace] [system.db.CDbCommand] Executing SQL: DELETE FROM `accounts` WHERE `active` = ':active' AND (`name` LIKE ':name' OR `email` LIKE ':email')



  1. Are the parameters not being bind? or the query is logged before binding parameters? if the second question has yes answer then how can I log the final generated query?

Firas.

To see params’ values, you have to enable “paramLogging” in your database connection config: http://www.yiiframework.com/doc/api/CDbConnection#enableParamLogging-detail

  • There is no need to put " ’ " around placeholders.

  • Do you use LIKE instead of “=”? If not, didn’t you forget “%” or “_” sybmols?

P.S. I think, the next syntax better suits your situation:




Account::model()->deleteAll(

    "`active` = :active AND (`name` LIKE :name OR `email` LIKE :email)",

    array(':active' => self::INACTIVE, ':name' => $name, ':email' => $email)

));



Thank you for your answer, it works with me when I removed the " ’ ". also parameters are being logged after enabling paramLogging.

Thanks.