简体   繁体   English

Zend框架查询where子句

[英]Zend framework query where clause

I have the following query for searching the tables by car model no and category name 我有以下查询,用于按汽车型号和类别名称搜索表格

SELECT * FROM CARS as car 
LEFT JOIN CATEGORIES as cat 
ON cat.car_id = car.car_id 
WHERE (car.model_no LIKE '%GT V8%') OR (cat.name LIKE '%GT V8%')

I am using zend framework so I have the query like this so far in my model 我正在使用zend Framework,因此到目前为止,我的模型中都存在这样的查询

$sql = $this->select()->setIntegrityCheck(false)
            ->from(array('car'=>$this->_name), array())
            ->joinLeft(array('cat'=>'categories'), 'cat.car_id=car.car_id', array())

then in where clause 然后在where子句中

I do like this 我喜欢这样

$sql->where('car.model_no LIKE ?', '%'.$query['search'].'%')
    ->where('cat.name LIKE ?', '%'.$query['search'].'%')

but that output like 但是输出像

WHERE (car.model_no LIKE '%GT V8%') AND (cat.name LIKE '%GT V8%')

I just can't find a way to replace AND with OR.. Is there anyway to do that in zend_db? 我只是找不到用OR替换AND的方法。无论如何,在zend_db中有这样做吗?

Use orWhere (Example #19) 使用或在哪里 (示例#19)

$sql->where('car.model_no LIKE ?', '%'.$query['search'].'%')->orWhere('cat.name LIKE ?', '%'.$query['search'].'%')

From the docs: 从文档:

If you need to combine terms together using OR, use the orWhere() method. 如果您需要使用OR将术语组合在一起,请使用orWhere()方法。 This method is used in the same way as the where() method, except that the term specified is preceded by OR, instead of AND. 此方法的使用方式与where()方法相同,不同之处在于,指定的术语以OR(而不是AND)开头。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM