Zend Framework 2,使用select

时间:2014-08-22 11:58:13

标签: php zend-framework orm zend-framework2

这是我需要从zend ORM中创建的SQL。它作为sql工作,但我需要从zend2 ORM重新创建它,当我获取'type'列的数据时,如果数据来自table1它应该检索'type1',当它来自{ {1}},应为table2

'type2'

我在zend2中使用了类似的东西,但没有给我正确的值。

select id,'type1' as type
from table1
UNION
select id,'type2' as type
from table2 where id = 1

1 个答案:

答案 0 :(得分:0)

找到答案,

$ select-> from(array(' a' =>' table1'));     $选择 - >柱(阵列(         " ID&#34 ;,         '类型' =>新表达("' type1'")     ));

$select2->from(array('t2' => 'table2'));
$select2->columns(array(
    "id",
    'type' => new Expression("'type2'")
));
$select->combine ( $select2 );