ZF2 How to orWhere()

前端 未结 2 1833
我在风中等你
我在风中等你 2020-12-15 08:37

I am trying to figure out how to make a Mysql Select with an OR in where Clause. By default all clauses in where statement are ANDed and after some hours of try and fail and

相关标签:
2条回答
  • 2020-12-15 08:54

    There is no orWhere in ZF2, but you could use any combination of Zend\Db\Sql\Predicate objects. For OR use 2 predicates in a PredicateSet with PredicateSet::COMBINED_BY_OR.

    There's not much documentation for it, but you could browse the source - for now.

    Edit: sample

    use Zend\Db\Sql\Predicate;
    
    $select->where(array(
        // ...
        new Predicate\PredicateSet(
            array(
                new Predicate\Like('content', '%'.$searchstring.'%'),
                new Predicate\Like('title', '%'.$searchstring.'%'),
            ),
            Predicate\PredicateSet::COMBINED_BY_OR
        ),
        // ...
    ));
    
    0 讨论(0)
  • 2020-12-15 09:08

    or you cloud use:

    $select->where
        ->like('content','%'.$searchstring.'%')
        ->or
        ->like('title','%'.$searchstring.'%');
    
    0 讨论(0)
提交回复
热议问题