How to pass a list of strings to an IN condition?

Hi, I need to delete a bunch of records, using strings as the keys, which come in an array, for instance:

array(‘apple’, ‘blahblah’, ‘johny’);

So, I need to delete the 3 records, and I’d like to do it this way:

$keys = array(‘apple’, ‘blahblah’, ‘johny’);

$criteria = new CDbCriteria();

$criteria->condition = ‘names IN (:keys)’;

$criteria->params = array(’:keys’ => $keys);


But it doesn’t work. I’ve tested with integers as keys, and it works.

You would need to use addInCondition:

$keys = array('apple', 'blahblah', 'johny');

$criteria = new CDbCriteria();

$criteria->addInCondition('names', $keys);


Puf, I totally missed this one. Thanks a lot.