Silverboy.ir
Silverboy.ir

Reputation: 187

use zend db with whare and orwhere when orwhere are in ()

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?

Upvotes: 4

Views: 7579

Answers (1)

Tim Fountain
Tim Fountain

Reputation: 33148

You want:

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

Upvotes: 9

Related Questions