ZF-2142: Allow the where() method of Zend_Db_Select to accept multiple arguments for automatic quoting

Issue Type: Improvement Created: 2007-11-04T13:53:24.000+0000 Last Updated: 2012-05-05T23:37:34.000+0000 Status: Reopened Fix version(s): - Next Major Release ()

Reporter: Marc Richards (talawahdotnet) Assignee: Ralph Schindler (ralph) Tags: - Zend_Db_Select

Related issues: - ZF-2228



Currently the where method of Zend_Db_Select allows to call the where() method with a second parameter that gets quoted substituted into the first parameter and replaces the placeholder (question mark). Since the where() method can be called multiple times, multiple parameters can be quoted.

<pre class="highlight">
$select = $db->select()
    ->where("product_name = ?", $prod)
    ->where("price < ?", $minimumPrice)
    ->orWhere("price > ?", $maximumPrice);

Unfortunately this usage makes it more difficult when you need to evaluate Boolean expressions in a specific order. In certain cases it becomes necessary to use the non-quoted format in order to clarify the query because AND has higher precedence than OR. Quoting must be done separately.

<pre class="highlight">
$minPriceQuoted = $db->quote($minimumPrice);
$maxPriceQuoted = $db->quote($maximumPrice);
$select = $db->select()
    ->where("product_name = ?", $prod)
    ->where("price < $minPriceQuoted OR price > $maxPriceQuoted");

If the where() method accepted multiple parameters for quoting, the usage would be much less awkward:

<pre class="highlight">
$select = $db->select()
    ->where("product_name = ? AND (price < ? OR price > ?)", $prod, $minimumPrice, $maximumPrice);


Posted by Darby Felton (darby) on 2007-11-05T14:46:19.000+0000

Assigning to [~thomas].

Posted by Thomas Weidner (thomas) on 2007-11-17T07:07:35.000+0000

Integrated to trunk... Please check SVN8640 or later and give us feedback.

Posted by Thomas Weidner (thomas) on 2007-11-22T03:08:35.000+0000

Solution not accepted by community and main author. Reverted the changes.

Posted by Thomas Weidner (thomas) on 2007-11-22T03:35:46.000+0000

Unassigned as original additional where methodology was not accepted.

Posted by Thomas Weidner (thomas) on 2008-01-25T13:41:44.000+0000

Integrated with SVN7576. Cored with Release 1.5

Posted by Thomas Weidner (thomas) on 2008-03-12T13:01:17.000+0000

Erased from core for review of complete component

Posted by Ralph Schindler (ralph) on 2009-01-10T10:31:46.000+0000

Will evaluate within 2 weeks

Have you found an issue?

See the Overview section for more details.


© 2006-2018 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.