php - Alias in ZF2 select - with calculated field -
i want create following query zf2:
select (a + b) c ta c > 1;
with table ta
contain 2 integer fields a
, b
.
i tried far code:
$columns = array('c'=>'(a + b)'); $where = 'c > 1'; $tablegateway = $this->gettablegateway('ta'); $sql = $tablegateway->getsql(); $select = $sql->select()->columns($columns); $select->where($where); $itemdata = $tablegateway->selectwith($select);
unfortunately query given is:
select `ta`.`a + b` `c` `ta` c > 1;
any idea how achieve that? tried without brackets: $columns = array('c'=>'a + b');
not work either.
i've tried before $this->getadapter()->query($sqlquery, adapter::query_mode_execute);
have run unbuffered query issue not resolvable ->closecursor()
.
use zend\db\sql\predicate\expression
:
$columns = array('c'=> new expression('(ta.a + ta.b)'));