Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add Sql\Expression in front of column Name in ZF2?

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.

like image 949
samsonasik Avatar asked Jan 07 '13 06:01

samsonasik


2 Answers

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.

like image 170
kuldeep.kamboj Avatar answered Nov 08 '22 03:11

kuldeep.kamboj


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');
like image 5
Tarun Singhal Avatar answered Nov 08 '22 05:11

Tarun Singhal