【问题标题】:php zf2 multiple wherephp zf2 多个where
【发布时间】:2016-04-02 05:09:26
【问题描述】:

我前段时间提出了一个问题:php zf2 select where clause with SQL function

但我回来了,因为我仍然遇到同样的问题。我可能很“愚蠢”,但我真的不明白为什么,无法实现过于简单的 SQL 查询的目标让我感到沮丧。

这是我在 ZF 2.3.5 之前运行良好的初始查询:

$select->where('(("' . $from . '" >= start_date AND "' . $from . '" < end_date ) OR ("' . 
$to . '" > start_date AND "' . $to . '" <= end_date ) OR ("' . 
$from . '" < start_date AND "' . $to . '" > start_date ))');

使用 ZF 2.4.9,我得到以下信息:

无法从接口 Zend\Db\Sql\Predicate\PredicateInterface 继承先前继承的或覆盖常量 TYPE_IDENTIFIER

我已经尝试了所有我能做的,甚至有一个非常小而简单的子句。它仍然给我上面的错误:

$select->where(array(new Zend\Db\Sql\Predicate\Expression("start_date <= $from")));
$select->where("start_date <= $from");
$select->where("`start_date` <= $from");
$select->where("`s`.`start_date` <= $from");
$select->where("`s`.`start_date` <= " . $from);
$select->where("`s`.`start_date` <= '" . $from. "'");

非常感谢您帮助我们了解发生了什么,以及如何解决这个问题。

【问题讨论】:

    标签: php sql zend-framework2 where


    【解决方案1】:
    $select = new Select();
    $select->where->addPredicates(array(
        new Predicate\Operator(
            'start_date',
            Predicate\Operator::OP_LTE,
            $from
        ),
        new Predicate\Operator(
            'end_date',
            Predicate\Operator::OP_GT,
            $from
        ),
    ));
    

    更多信息http://framework.zend.com/manual/current/en/modules/zend.db.sql.html#zend-db-sql-where-zend-db-sql-having

    或者这个更简单

    $select->where(array(
        'start_date <= ?' => $from,
        'end_date > ?' => $from
    ));
    

    【讨论】:

      猜你喜欢
      • 2015-11-16
      • 1970-01-01
      • 2016-11-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多