zend framework - Grouping WHERE clauses with Zend_Db_Table_Abstract -
Does anyone know the way to the group, where segment with Zend_Db? Basically I have this question
$ sql = $ table- & gt; Select () - & gt; Where ('company_id =?', $ Company_id) - & gt; Where ('client_email =?', $ Client_email) - & gt; Or where ('client_email_alt =?', $ Client_email);
This is giving me:
SELECT `clients'. * From 'Clients' WHERE (company_id = '1') and (client_email = 'Email@address.com') or (client_email_alt = 'email@address.com')
But me This is required, where or the statement is grouped:
SELECT 'clients'. * From customers WHERE (company_id = '1') AND ((client_email = 'email@address.com') or (client_email_alt = 'email@address.com'))
To achieve this, you will need to create a grouped section within a call where
method.
If both values of the circumstances are the same, then you can:
$ select-> where ('client_email =? Or client_email_tault =?', $ Client_email )
If there are many placeholders within the string, the quoteInto
method of the DB adapter will replace all the placeholders.
If you need to have a or
group with different values for each field, you must manually quote the value. It's a bit more complex:
$ select-> Where ($ db-> quoteInto ('client_email =?', $ Email1). 'Or'. $ Db- & gt; in quotation ('Client_email_alt =?', $ Email2)); Your example of // $ db is Zend_Db_Adapter_ * // You can get it from a Zend_Db_Table_Abstract // subclass by calling it getendext () method
Comments
Post a Comment