1

I'm trying to change this normal SQL statment, where I use "where" with or, to a Zend\Db\Sql\Sql Object.

However I cant figure out how to write the "where" clause.

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(?);
3
  • 1
    What class are you using? Commented Apr 17, 2014 at 8:48
  • it is Zend\Db\Sql\Sql Commented Apr 17, 2014 at 8:50
  • $sql->where(array('id = ?' => $id)); would work, too. Commented Apr 17, 2014 at 10:07

1 Answer 1

3

In simple case, only have 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)
Sign up to request clarification or add additional context in comments.

1 Comment

Could you shift your answer? Moving the simple case solution on top and the extended version for complex statements to the bottom? For reference purposes? :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.