Search code examples
zend-frameworkzend-db

Zend Framework Complex Where Statement


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")


Solution

  • 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);