查询之间的Zend框架

时间:2012-03-14 09:47:01

标签: zend-framework zend-db

如何在Zend Framework中编写以下查询?

select * from hosted_plans where hp_id=15 and curdate() between discount_start_date and discount_end_date

在上面的查询中,discount_start_date和discount_end_date列是表格中的日期字段

提前致谢。

3 个答案:

答案 0 :(得分:4)

$query = $database->select ()
    ->from ('hosted_plans')
    ->where ('hp_id = ?', 15)
    ->where ('curdate() between discount_start_date and discount_end_date');

$ database是Zend_Db_Adapter_Abstract后代。

答案 1 :(得分:2)

Zend 2的一种可能形式:

    $select = $this->tableGateway->getSql()->select();
    $select->where(array('hp_id' => 15, new \Zend\Db\Sql\Predicate\Expression('curdate() BETWEEN discount_start_date AND discount_end_date')));
    $resultSet = $this->tableGateway->selectWith($select);

答案 2 :(得分:1)

可替换地: -

$query = $database->select ()
    ->from('hosted_plans')
    ->where('hp_id = ?', 15)
    ->where('curdate() >= discount_start_date')
    ->where('curdate() <= discount_end_date');

也可以。