PHP Zend_Db_Statement_DB2为静态字段返回null


PHP Zend_Db_Statement_DB2 returns null for static field

我通过PHP API构建我的SQL语句,然后通过连接到我们的数据库(DB2)的模块传递它。

我的问题:当通过Zend_Db_Statement_DB2模块传递SQL时,静态字段 (sales_type)返回null。直接在AS400(命令行)上运行SQL,它可以正常工作。当我通过DB2模块传递相同的SQL时,"sales_type"字段对于所有行都为空。

查询的简化版本:

SELECT 'discount' "sales_type", sum(sales_type1) "sales" FROM salesTable
UNION
SELECT 'promotion' "sales_type", sum(sales_type2) "sales" FROM salesTable

虚构销售额的预期/期望结果(也在命令行返回):

sales_type     sales
discount       12345
promotion       6789

SQL通过DB2模块时返回的结果:

sales_type     sales
null           12345
null            6789
用于执行select查询的PHP代码如下所示:
    public static function ExecuteSelect($sql)
{
    $adapter = new Zend_Db_Adapter_Db2(Zend_Registry::get('config')->resources->multidb->as400)
    //Prepare the SQL Statement
    $sqlStmt = new Zend_Db_Statement_DB2($adapter, $sql);
    $sqlStmt->execute();
    $rows = $sqlStmt->fetchAll();
    return $rows;
}

谁能给我更多的见解,这个问题的原因和如何解决它?此外,我不是在寻找一个后处理php的工作方式。提前感谢!

请参阅下面的链接以获得解决方案。对于用户和运行查询的作业,CCSID都需要设置为37

PHP/SQL -将EBCDIC转换为ASCII