Doing a global OR with the db abstraction layer
It is possible to nest db_and() and db_or() calls, and pass the result into a condition() call. See Conditional Clauses documentation page for more information.


  The first parameter of condition() can also accept another conditional
  object. That inner conditional object will be incorporated into the
  outer conditional, surrounded by parentheses. The inner object may
  also use a different conjunction than the outer object. That way, one
  can build complex nested conditional structures by creating and
  building up conditional objects "bottom up".
  
  The db_condition() helper function will return a new conditional
  object. It takes a single parameter that is the conjunction that
  object will use. In general, the helper methods db_and(), db_or(), and
  db_xor() will cover almost any expected case. That allows conditionals
  to be inserted inline in a query for a very compact syntax.


function a() {
  $q = db_select('table', 't');
  $q-&gt;addField('t', 'field1');
  $q-&gt;condition(db_or()-&gt;condition(b($q))-&gt;condition('t.field3', 'some val', '=');
  $q-&gt;execute();
}

function b($q) {
  return db_and()
    -&gt;condition('t.field1', 'some val', '=');
    -&gt;condition('t.field2', 'some val', '=');
}


This should produce the query SELECT field1 FROM table t WHERE ((t.field1 = 'some val' AND t.field2 = 'some val') OR (t.field3 = 'some val')).