【问题标题】:PHP Zend_Db_Statement_DB2 returns null for static fieldPHP Zend_Db_Statement_DB2 为静态字段返回 null
【发布时间】:2013-05-01 21:31:07
【问题描述】:

我正在通过 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

用于执行选择查询的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 解决方法。提前致谢!

【问题讨论】:

    标签: php sql db2 zend-db


    【解决方案1】:

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

    PHP / SQL - Convert EBCDIC to ASCII

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-10
      相关资源
      最近更新 更多