简体   繁体   English

OR,和使用Zend \\ Db \\ Sql \\ Sql的Where

[英]OR, AND with Where by using Zend\Db\Sql\Sql

I'm trying to change this normal SQL statment, where I use "where" with or, to a Zend\\Db\\Sql\\Sql Object. 我正在尝试更改这个正常的SQL语句,我在其中使用“where”和,或者Zend\\Db\\Sql\\Sql对象。

However I cant figure out how to write the "where" clause. 但是我无法弄清楚如何编写“where”子句。

this is the code before: 这是以前的代码:

 SELECT column 
 FROM Table
 WHERE value = num OR value2 = num

and this is how i'm trying to make it look like: 这就是我试图让它看起来像:

 $sql = new Sql($adapter);
 $select = $sql->select();
 $select->from(Table);
 $select->where(?);

In simple case, only have AND. 在简单的情况下,只有AND。 You can use 您可以使用

$select ->where(array('cloumn1'=>'A', 'column2'=>'B'));

In complex case: 在复杂的情况下:

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM