How to get Sql like this :
select * from foo where LOWER(foo_name) = 'test';
what i get is if Sql\Expression in right, not in left.
You can user code snippet like that.
$where = new Where();
$sql = new Sql($adapter);
$select = $sql->select();
$where->addPredicate(new Predicate\Expression('LOWER(foo_name) = ?', 'test' ));
$select->from('foo')->where($where);
However I dont think Sql\Expression on right side is possible on Zend Framework 2.
You can do it like this:
$sql = new SQL($adaptor);
$select = $sql->select()->from(array('f'=>'foo'));
$select = $select->where('foo_name' => new \Zend\Db\Sql\Expression("LOWER('test')"));
Above query would return as:
SELECT `f`.* FROM `foo` AS `f` WHERE `foo_name` = LOWER('test');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With