We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Nested PHQL Query Conditions with Query Builder

Is there a way to nest/group conditions with the OO PHQL query builder?

Say in raw SQL you have SELECT id, name FROM table WHERE (id = 1 AND name = 2) OR (id = 1 AND name = 3)

With the query builder $queryObj->from('table') ->columns(array('id','name')) ->where('id = 1') ->andWhere('name = 2') ->orWhere(...) // nesting/grouping breaks down/un-expected nesting after this point



15.1k

Try specifying more than one condition within a single where block:

$queryObj->from('table') 
   ->columns(array('id','name'))
   ->where('id = 1 AND xx = 2')
   ->orWhere('id = 2 AND xx = 1');