<p>I am trying to use Zend_Db_Select to write a select query that looks somewhat like this:</p>

<pre><code>SELECT * FROM bar WHERE a = 1 AND (b = 2 OR b = 3)
</code></pre>

<p>However, when using a combination of where() and orWhere(), it seems impossible to use condition grouping like the above.</p>

<p>Are there any native ways in Zend Framework to achieve the above (without writing the actual query?)</p>

[{'answer_id': 80871, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 3, 'selected': True, 'text': '<p>From <a href="http://framework.zend.com/manual/en/zend.db.select.html#zend.db.select.building.where" rel="nofollow noreferrer">the manual</a> (Example 11.61. Example of parenthesizing Boolean expressions)</p>\n\n<pre><code>\n// Build this query:\n//   SELECT product_id, product_name, price\n//   FROM "products"\n//   WHERE (price &lt; 100.00 OR price &gt; 500.00)\n//     AND (product_name = \'Apple\')\n\n$minimumPrice = 100;\n$maximumPrice = 500;\n$prod = \'Apple\';\n\n$select = $db->select()\n             ->from(\'products\',\n                    array(\'product_id\', \'product_name\', \'price\'))\n             ->where("price &lt; $minimumPrice OR price &gt; $maximumPrice")\n             ->where(\'product_name = ?\', $prod);\n\n</code></pre>\n'}, {'answer_id': 727266, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': '<p>The above reference is great, but what if you are playing with strings?</p>\n\n<p>Here would is the above example with strings...</p>\n\n<pre><code>// Build this query:\n//   SELECT product_id, product_name, price\n//   FROM "products"\n//   WHERE (product_name = \'Bananas\' OR product_name = \'Apples\')\n//     AND (price = 100)\n\n$name1 = \'Bananas\';\n\n$name2 = \'Apples\';\n\n$price = 100;\n\n$select = $db-&gt;select()\n\n-&gt;from(\'products\',\n                    array(\'product_id\', \'product_name\', \'price\'))\n\n-&gt;where("product_name = \'" . $name1 . "\' OR product_name = \'" . $name2 . "\'")\n\n-&gt;where("price=?", $price);\n</code></pre>\n\n<p>I hope that helps. Took me some fooling around to get the strings to work correctly.</p>\n\n<p>Cheers.</p>\n'}]
['https://Stackoverflow.com/questions/80846', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/11568/']