4

hi i want create this sql in zend framework dbclass

selec * from table where type = 2 AND (name LIKE '%4%' OR name LIKE '%5%')

how i can do this with zend where and orwhere?

using normal mode will generate this sql

 $this->select()->from($this->_name)->where('type = ?', $type)->orwhere('name LIKE ?', '%'.4.'%');

this is not what i need

also i think i can use having in this case , is this a good idea?

Silverboy.ir
  • 187
  • 2
  • 11
  • You can't group where clauses on Zend. The only solution is as in @Tim Fountain's answer - to group clauses like a normal query string. Note: I'm not sure for `ZF2`, maybe there is a solution for this. – enenen May 16 '13 at 08:46
  • thanks but i used $this->select()->from($this->_name)->having('type = ?', $type)->orwhere('name LIKE ?', '%'.4.'%'); now it's work ... is this a good statement ? – Silverboy.ir May 16 '13 at 14:56
  • If this didn't work for you, try this: http://stackoverflow.com/questions/1179279/grouping-where-clauses-with-zend-db-table-abstract – Jeremy Harris Jul 17 '15 at 19:12

1 Answers1

9

You want:

$this->select()
     ->from($this->_name)
     ->where('type = ?', $type)
     ->where('name LIKE ? OR name LIKE ?', array('%'.4.'%', '%'.5.'%');
Tim Fountain
  • 33,093
  • 5
  • 41
  • 69