dqb14659
2014-07-08 00:16
浏览 34
已采纳

如何在ZF2中结合较低和喜欢?

How to get SQL like this :

select * from foo where LOWER(foo_name) like '%test%'; 

I know that I can achieve this:

select * from foo where LOWER(foo_name) = 'test';

By:

$where->addPredicate(new Predicate\Expression('LOWER(foo_name) = ?', 'test' ));

And this:

 select * from foo where foo_name like '%test%';

By:

$where->addPredicate( new \Zend\Db\Sql\Predicate\Like('LOWER(foo_name)', '%test%'));

But how to combine the two?

图片转代码服务由CSDN问答提供 功能建议

如何获取 SQL ,如下所示:

  select f from foo,其中LOWER(foo_name)喜欢'%test%';  
   
 
 

我知道我可以做到这一点:

  select f from foo where LOWER(foo_name)='  test'; 
   
 
 

通过:

  $ where-> addPredicate(new Predicate \ Expression('LOWER)  (foo_name)=?','test')); 
   
 
 

这个:

  select * from  foo,其中foo_name喜欢'%test%'; 
   
 
 

By:

  $ where-> addPredicate(  new \ Zend \ Db \ Sql \ Predicate \ Like('LOWER(foo_name)','%test%')); 
   
 
 

但如何组合< em>两个

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • duanfei1268 2014-07-08 08:49
    已采纳

    Answer given by @dave works fine.

    Even this works -

    $where->expression("LOWER(title) LIKE ?", '%test%');
    
    已采纳该答案
    评论
    解决 无用
    打赏 举报
  • douxin1884 2014-07-08 00:34

    Probably not ideal, but you could do literal:

    $where->literal("LOWER(foo_name) LIKE '%test%'");
    
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题