有人可以指导我使用Zend db select编写如下的查询:
SELECT `tbl_md_users`.*
FROM `tbl_md_users`
WHERE
user_type <> 'TYPE1')
AND (first_name LIKE '%tom%' OR last_name LIKE '%tom%' OR user_name LIKE '%tom%')
答案 0 :(得分:6)
如果你想
SELECT `tbl_md_users`.*
FROM `tbl_md_users`
WHERE
user_type <> 'TYPE1')
AND (first_name LIKE '%tom%' OR first_name LIKE '%dick%' OR first_name LIKE '%harry%')
然后第一个答案不起作用
我使用了Zend_Db_Expr
$likeTom = new Zend_Db_Expr("first_name LIKE '%tom%'");
$likeDick = new Zend_Db_Expr("first_name LIKE '%dick%'");
$likeHarry = new Zend_Db_Expr("first_name LIKE '%harry%'");
$query = $database->select ()
->from ('tbl_md_users')
->where ('user_type <> ?', 'TYPE1')
->where ("{$likeTom} OR {$likeDick} OR {$likeHarry}");
答案 1 :(得分:4)
$query = $database->select ()
->from ('tbl_md_users')
->where ('user_type <> ?', 'TYPE1')
->where ("first_name LIKE '%?%' OR last_name LIKE '%?%' OR user_name LIKE '%?%'", 'tom');
答案 2 :(得分:1)
当前的最新解决方案是在where子句中调用nest()和unnest():
$select->where
->nest()
->equalTo('column1', 1)
->or
->equalTo('column2', 2)
->unnest()
->and
->equalTo('column3', 3);
答案 3 :(得分:0)
我认为没有办法使用Zend_Db_Select。你可以用
$this->table->getAdapter()->quoteInto()
编写自定义查询。