How to specify multiple conditions and the type of condition using Zend_Db_Table
I have a function in my model that I need to use multiple conditions when querying. Additionally I would like to also have partial matches.
I currently have:
public function searchClient($search_term)
{
$rows = $this->fetchAll(
开发者_运维问答 $this->select()
->where('first_name = ?', $search_term)
);
return $rows->toArray();
}
Which is the equivalent of "SELECT * FROM clients WHERE first_name = 'foobar';"
I would like to have a function that is the equivalent of "SELECT * FROM clients WHERE first_name LIKE '%foobar%' OR last_name LIKE '%foobar%' OR home_phone LIKE '%foobar%';"
How would I create such a query within Zend_Db_Table?
public function searchClient($search_term)
{
$rows = $this->fetchAll(
$this->select()->where('first_name LIKE ?', "%$search_term%")
->orWhere('last_name LIKE ?', "%$search_term%")
->orWhere('home_phone LIKE ?', "%$search_term%")
);
return $rows->toArray();
}
精彩评论