Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8412023
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T00:34:20+00:00 2026-06-10T00:34:20+00:00

Possible Duplicate: Zend Framework Complex Where Statement How do I add something like this

  • 0

Possible Duplicate:
Zend Framework Complex Where Statement

How do I add something like this to a Zend_Db_Select while still using quoting?

SELECT x FROM y WHERE (a=1 OR b=2) AND (c=3 OR d=4)

I have seen where() and orWhere(), but I see no way of grouping them with brackets. I realize that I could just write this:

->where('(a=1 OR b=2) AND (c=3 OR d=4)')

But ideally I would like to have 4 separate calls to where() to be able to use the second parameter for quoting (assuming the values 1, 2, 3 etc. are user generated input).

Is there any way to do this in the pure fluent style?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T00:34:22+00:00Added an answer on June 10, 2026 at 12:34 am

    Is there any way to do this in the pure fluent style?

    Short answer: no.

    As you mention, you can use orWhere to write conditions like (a = ?) OR (b = ?).

    Zend_Db_Select automatically puts parentheses around each expression you specify using the where() or orWhere() methods. This helps to ensure that Boolean operator precedence does not cause unexpected results.

    However it is not possible to nest AND and OR conditions in the way you wish.

    If you wrote this:

    ->where('a=?', $a)
    ->orWhere('b=?', $b)
    ->where('c=?', $c)
    ->orWhere('d=?', $d)
    

    It would result in SQL similar to this:

    (a=1) OR (b=2) AND (c=3) OR (d=4)
    

    Which would be interpreted as follows (not what you want):

    (a=1) OR ((b=2) AND (c=3)) OR (d=4)
    

    Alternatives:

    • Write the SQL by hand.
    • Use quoteInto as demonstrated here.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Grouping WHERE clauses with Zend_Db_Table_Abstract I need to create something like this:
Possible Duplicate: Zend Framework: Model class not found I am using ZF 1.11 and
Possible Duplicate: How do I add a limit to update-query in Zend Framework? I
Possible Duplicate: Zend Framework - multiplate navigation blocks I'm trying to make breadcrumbs render
Possible Duplicate: Use Zend Framework components without the actual framework? I just need the
Possible Duplicate: What is the difference between redirect and forward in Zend framework Please
I would like to use ON DUPLICATE KEY UPDATE in Zend Framework 1.5, is
Possible Duplicate: What are Zend Framework “Resources”? Is there any definition on what is
Possible Duplicate: Zend Framework: Controller Plugins vs Action Helpers I know what the difference
Possible Duplicate: change layout and template in zend dynamically according to the device(android tab,iphone,ipad)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.