如何使用Zend_Db_Table指定多个条件和条件类型

时间:2010-05-11 21:48:28

标签: php zend-framework

我的模型中有一个函数,我在查询时需要使用多个条件。另外我想也有部分匹配。

我目前有:

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中创建这样的查询?

1 个答案:

答案 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();
}