简体   繁体   中英

PHP Zend_Db_Statement_DB2 returns null for static field

I am building my SQL statement through a PHP API, and then passing it through a module that connects to our database (DB2).

My issue: a static field (sales_type) is returning null when passing the SQL through a Zend_Db_Statement_DB2 module. Running the SQL directly on our AS400 (command line), it works properly. When I pass the same SQL through the DB2 module the "sales_type" field is null for all rows.

A simplified version of the query:

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

Expected/Desired results with fictiscious sales (what is also returned on command line):

sales_type     sales
discount       12345
promotion       6789

Returned results when SQL passed through DB2 module:

sales_type     sales
null           12345
null            6789

The PHP code used to execute select queries is listed below:

    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;
}

Can anyone give me more insight as to the cause of this issue and how to fix it? Also, I'm not looking for a post-processing php work-around. Thanks in advance!

Please see this link posted below for a solution. The CCSID needs to be set to 37 for both the user and the job running the query

PHP / SQL - Convert EBCDIC to ASCII

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM