Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Zend-framework DB: OR instead of AND operator

have such zend query:

$select = $this->_table
               ->select()
               ->where('title LIKE  ?', '%'.$searchWord.'%')
               ->where('description LIKE  ?', '%'.$searchWord.'%')
               ->where('verified=1 AND activated=1');

In other words it looks like:

SELECT `some_table`.* FROM `some_table` WHERE (title LIKE '%nice house%') AND (description LIKE '%nice house%') AND (verified=1 AND activated=1)

If I have couple AND sentences, zend connect it through AND operator. How can I connect it with OR operator ? Cause I need:

...(title LIKE '%nice house%') OR (description LIKE '%nice house%')...

Your help would be appreciated.

like image 797
Bounce Avatar asked Aug 21 '10 07:08

Bounce


3 Answers

$this->_table->select()->orWhere($condition);

To build more complexe queries (i.g. sub-conditions) you might have to use $this->table->getAdapter()->quoteInto() and write your SELECT manually.

like image 142
Yanick Rochon Avatar answered Oct 21 '22 23:10

Yanick Rochon


The others answers here do not work (anymore?), the current solution is to call nest() and unnest() in the where clause:

$select->where
    ->nest()
        ->equalTo('column1', 1)
        ->or
        ->equalTo('column2', 2)
    ->unnest()
    ->and
    ->equalTo('column3', 3);
like image 34
Andreas Avatar answered Oct 21 '22 23:10

Andreas


I have implemented your zend query

$select = $this->_table
               ->select()
               ->where('title LIKE  ?', '%'.$searchWord.'%')
               ->ORwhere('description LIKE  ?', '%'.$searchWord.'%')
               ->where('verified=1 AND activated=1');
like image 1
SagarPPanchal Avatar answered Oct 21 '22 23:10

SagarPPanchal