1

How can I write the following query in Zend Framework?

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

In the query above the discount_start_date and discount_end_date columns are date fields in the table

Thanks in advance.

3 Answers 3

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

$database being a Zend_Db_Adapter_Abstract descendant.

Sign up to request clarification or add additional context in comments.

Comments

2

One possible form with 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);

Comments

1

Alternatively:-

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

Would also work.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.