我的模型中有一个函数,我在查询时需要使用多个条件。另外我想也有部分匹配。
我目前有:
public function searchClient($search_term)
{
$rows = $this->fetchAll(
$this->select()
->where('first_name = ?', $search_term)
);
return $rows->toArray();
}
这相当于“SELECT * FROM clients WHERE first_name ='foobar';”
我希望有一个功能,相当于“SELECT * FROM clients WHERE first_name LIKE'%foobar%'或last_name LIKE'%foobar%'或home_phone LIKE'%foobar%';”
我如何在Zend_Db_Table中创建这样的查询?
答案 0 :(得分:1)
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();
}