Search code examples
phpsymfonyormdoctrine-orm

Doctrine2 Querybuilder bitwise and


I would like to use a bitwise comparison in my Doctrine2/Symfony2 QueryBuilder. I tried

->andWhere('n.sharingenabled & 1')

And

->andWhere('BIT_AND(n.sharingenabled, 1)')

but they both threw the following error

QueryException: [Syntax Error] line 0, col 327: Error: Expected =, <, <=, <>, >, >=, !=, got '&'


Solution

  • You need to compare the BIT_AND result to something ... for example :

    ->andWhere('BIT_AND(n.sharingenabled, 1) > 0')