我需要在查询中添加特殊运算符。查询:
SELECT "contests".*
FROM "contests" WHERE "status" = '-1'
AND "level1" = '1' AND "level2" = '1' AND "level3" = '1' AND "level10" = '1'
AND DATE(`contests`.`start`) >= '2012-03-17' AND DATE(`contests`.`stop`) <= '2013-12-20'
在Zend Framework 2中:
$from = '2012-03-17';
$to = '2013-12-20';
$sql = new Sql($this->adapter);
$select = $sql->select('contests')
->where($where, $combination = new Predicate\Operator($from, Predicate\Operator::OPERATOR_GREATER_THAN_OR_EQUAL_TO, $to));
但这不起作用。
答案 0 :(得分:4)
如果你写下这样的where子句怎么样: -
$select->where->equalTo('status', '-1');
$select->where->equalTo('level1', '1');
等
$select->where->greaterThanOrEqualTo('start', '2012-03-17');
$select->where->greaterThanOrEqualTo('stop', '2013-12-20');
答案 1 :(得分:1)
我正在使用表网关。使用起来更清楚。 你可以使用where子句。
public function getGelecek()
{
$select = $this->tableGateway->getSql()->select();
$select->where(array('active' => '1'));
$select->where->greaterThan('tarih', '123');
$resultset = $this->tableGateway->selectWith($select);
return $resultset;
}