Zend-framework DB: OR instead of AND operator

Bounce picture Bounce · Aug 21, 2010 · Viewed 20.5k times · Source

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.

Answer

Yanick Rochon picture Yanick Rochon · Aug 21, 2010
$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.