views:

34

answers:

2

This method is published as offical example

->where("price < $minimumPrice OR price > $maximumPrice") is such method safe?

want to write it as ->where("price < ? OR price > ?", $minimumPrice, $maximumPrice) are there any poissibility?

and I can't split it into 2 where statements because plan to write query ->where("1 OR 2") ->where("3 OR 4")

A: 

->where('(price < ?', $minPrice)

->orWhere('price > ?)', $maxPrice)

will result

where (price < $minPrice OR price > $maxPrice)

boosis
this is not suitable - I need to wrote construction like this ->where(->where(1) or ->where(2))->where(->where(3) or ->where(4))
se_pavel
+1  A: 

If I have complex WHERE clauses I use the db adapters' ->quoteInto() method like:

$where = '('
           . $dbAdapter->quoteInto('price1 < ?', $price1)
           . ' OR '
           . $dbAdapter->quoteInto('price1 > ?', $price1)
       . ')'
       . ' AND '
       . '('
           . $dbAdapter->quoteInto('price2 < ?', $price2)
           . ' OR '
           . $dbAdapter->quoteInto('price2 > ?', $price2)
       . ')'
       ;

$select->where($where);
Jason Austin
this is the valid variant, but it didn't nice :)
se_pavel