【问题标题】:Zend Framework 2, using selectZend Framework 2,使用选择
【发布时间】:2014-08-22 11:58:13
【问题描述】:

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

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

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

    $select->from(array('a' => 'table1'));
    $select->columns(array(
        "id",
        "'type1'" => "type"
    ));

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

【问题讨论】:

    标签: php zend-framework orm zend-framework2


    【解决方案1】:

    找到答案,

    $select->from(array('a' => 'table1')); $select->列(数组( “ID”, 'type' => new Expression("'type1'") ));

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多