Zend Framework 2 Sql Select with OR and AND

◇◆丶佛笑我妖孽 提交于 2019-11-30 07:10:38

from the top of the head using Where fluent interface:

$select->where
       ->nest
           ->equalTo('table2.column2', 2)
           ->or
           ->equalTo('table2.column3', 3)
       ->unnest
       ->and
       ->equalTo('table1.column1', 1);
Delio

I would do something like:

$where = new \Zend\Db\Sql\Where();

$where
    ->nest()
    ->equalTo('table2.column2', 2)
    ->or
    ->equalTo('table2.column3', 3)
    ->unnest()
    ->and
    ->equalTo('table1.column1', 1);
$select->where($where)

Just because this way your $select keep being an implementation of Zend\Db\Sql\SqlInterface while doing

$select->where
   ->nest

will return an instance of a Zend Sql operator. Which is not bad but then you can't just do

$statement = $sql->prepareStatementForSqlObject($select);
$resultSet = $statement->execute();
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!