ZF-2211: between support in select statement

Issue Type: New Feature Created: 2007-11-16T07:03:18.000+0000 Last Updated: 2012-05-05T23:18:27.000+0000 Status: Closed Fix version(s): Reporter: Grégoire ROBIN (nodashi) Assignee: Adam Lundrigan (adamlundrigan) Tags: - Zend_Db_Select

Related issues: - ZF-2228




I'd like to use the "BETWEEN" operator in my select statement. (ex : SELECT * FROM product WHERE price BETWEEN x AND y) Currently i don't see how i can do this. So I write my own function, I give it to you the code, but i think there is a better way to do the same thing cause in fact i just want to quote 2 values separatly. It should be better if the where function do something like that.

<pre class="literal"> 
    * $select->between('price BETWEEN ? ', 100, 200);

    public function between($cond)
        if (func_num_args() > 1) {
            $min  = $this->_adapter->quote(func_get_arg(1));
            $max  = $this->_adapter->quote(func_get_arg(2));
            $cond = str_replace('?', $min . ' AND ' . $max, $cond);

        if ($this->_parts[self::WHERE]) {
            $this->_parts[self::WHERE][] = "AND ($cond)";
        } else {
            $this->_parts[self::WHERE][] = "($cond)";

        return $this;


Posted by Thomas Weidner (thomas) on 2007-11-16T11:26:15.000+0000


The actual way would be

<pre class="highlight">
$this->where('price > ?', 100)->where('price < ?', 200);

I think "Between" is not supported by all adapters.

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

Unassigned as original additional where methodology was not accepted.

Posted by Thomas Weidner (thomas) on 2008-03-11T03:33:59.000+0000

Class will be reworked by Simon... sorry if I confused anybody. He has a better overview over the complete Db design, not only Zend_Db_Select and will help better than me.

Posted by Wil Sinclair (wil) on 2008-04-18T13:20:27.000+0000

Please evaluate and categorize as necessary.

Posted by Wil Sinclair (wil) on 2008-12-04T13:17:29.000+0000

Reassigning to Ralph since he's the new maintainer of Zend_Db

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

Will be evaluted with linked issue, I am not sure between is the correct addition where WHERE would be more intuitive

Posted by Adam Lundrigan (adamlundrigan) on 2012-05-05T23:18:27.000+0000

The BETWEEN operator is part of SQL-92 and AFAIK is well supported by the RDBMSes Zend_Db abstracts. I would favor implementation of ZF-2142 (Allow the where() method of Zend_Db_Select to accept multiple arguments for automatic quoting) instead of the OP's suggestion:

<pre class="highlight">
$select->where('price BETWEEN ? AND ?', 100, 200);

Closing as Won't Fix.

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.