开发者

Extending Zend DB Table to include BETWEEN and LIMIT

开发者 https://www.devze.com 2023-01-02 19:06 出处:网络
Am looking for how I can extend the Zend_DB_Table below to accomodate a BETWEEN two dates syntax and LIMIT syntax

Am looking for how I can extend the Zend_DB_Table below to accomodate a BETWEEN two dates syntax and LIMIT syntax

My current construct is

class Model_DbTable_Tablelist extends Zend_Db_Table_Abstract
{
    protected $_name = 'mytable';

    $select = $this->select()
                    ->setIntegrityCheck(false)
                    ->from('mytable',
              开发者_如何学C          array('MyCol1', 'MyDate'));

}

I want it extended to be equivalent to the query below

SELECT MyCol1,MyDate FROM mytable
WHERE MyDate BETWEEN '2008-04-03' AND '2009-01-02'
LIMIT 0,20

Any ideas?


Regarding BETWEEN, this issue was reported on the Zend site - it appears to still be open. The workaround mentioned is to use something like

$this->where('MyDate > ?', '2008-04-03')->where('MyDate < ?', '2009-01-02');

Looks like you can use the "limit" method to add a LIMIT clause to your SQL, e.g.

->limit(0, 20);

Share and enjoy.


$adapter = $this->getAdapter();

$dt = "datetime between ? and ? ";
$dt = $adapter->quoteInto($dt, "04-01-2010 ", null, 1);
$dt = $adapter->quoteInto($dt, "05-01-2010 ", null, 1);
$this->where($dt)


Note that ->limit(0,20) means no limit to the number of returned rows, but skip the first 20 rows.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号