I'm using Zend Framework 1.12.3. I need to create a query that hasnested WHEREs, such as
SELECT * FROM table1
WHERE (id = 'foo' AND name = 'bar') OR (grade = 123)
Here's my attempt
$this->getDbTable()->select()
->from($this->getDbTable(), array('*')
->where('id = ? AND name = ?', $foo, $bar)
->orWhere('grade = ?', $grade);
However, the outcome is
SELECT * FROM table1
WHERE (id = 'foo' AND name = 'foo') OR (grade = 123)
instead of name = 'bar'
Basically, I cannot use multiple ?
s assigning each ?
a different value. Do you know any solution?
Thanks
LE: using a WHERE condition such as ->where("id = $foo and name = $bar")
does work, however it doesn't prevent injection attacks like the ?
does