2011-11-08 32 views
0

是否有可能使用Zend_Db_Select對象那裏/ whereOr以這樣的方式,我可以這樣做:Zend 1.11.X框架多個Wheres?

$select->whereOr('field1 = ? field2 = ?', array($value1, $value2)); 
or 
$select->whereOr('field1 = ? field2 = ?', $value1, $value2); 

這將是不必記住逃脫變量自己輕鬆了許多。

回答

0

你可以這樣做:

$select->where('field1 = ?', $value1)->orWhere('field2 = ?', $value2); 
1

這要看具體情況,比如,如果你有兩個條件,並在其中每一個都有一個OR。

喜歡:

WHERE (col = $someValue OR col = $otherValue) OR (col2 = $thirdValue AND col2 = $fourthValue) 

這些都必須手動完成。我喜歡做這樣的:

$orWhere = array(
    "(col = {$someValue} OR col = {$otherValue})", 
    "(col2 = {$thirdValue} AND col2 = {$fourthValue})" 
); 

$select->where(implode(' OR ', $orWhere)); 

這是一個很好的有益的工作圍繞我的,因爲Zend_Db_Select對象如何表現它封裝每個where()orWhere()在括號中的那些情況。