How do I reproduce this SQL with Drupal 7's query builder?
You need to do something like this:

$query = db_select('mytable', t)-&gt;fields('t');
$condition = db_or();
foreach($mywords as $w {
  $condition-&gt;condition(db_and()-&gt;condition('myfield1', $w)-&gt;condition('myfield2', $w));
}
$result = $query-&gt;condition($condition)-&gt;execute();


This is not tested but should work.

For reference, see db_or and db_and