Operaciones bit a bit de Yii en CDbCriteria

I am trying to use bitwise operations when quering the DB using a CDbCriteria but am not having any luck; I can't find anything on the bitwise operators in the ::compare doctor. I am looking for something like this:

// only grab users that are not expired.

$criteria = new CDbCriteria;
$criteria->compare('flags','& ' . self::USER_EXPIRED . ' = 0',true);

however this is not working, is there a different function I need to be using?

preguntado el 08 de noviembre de 11 a las 14:11

1 Respuestas

¿Has probado usar addCondition() insted of compare()? I imagine something like this should work (though have not tested it):

$criteria = new CDbCriteria;
$criteria->addCondition('flags & ' . self::USER_EXPIRED . ' = 0');

Out of curiousity: why do you represent information like this in bits? You could use a dedicated column (expired) with enum values ('yes', 'no'), and your code would be a lot more readable and maintainable.

respondido 08 nov., 11:19

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.