0

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?

GingerHead
  • 8,130
  • 15
  • 59
  • 93

2 Answers2

2

Answer given by @dave works fine.

Even this works -

$where->expression("LOWER(title) LIKE ?", '%test%');
Kunal Dethe
  • 1,254
  • 1
  • 18
  • 38
1

Probably not ideal, but you could do literal:

$where->literal("LOWER(foo_name) LIKE '%test%'");
dave
  • 62,300
  • 5
  • 72
  • 93