ZF-4894: Zend_Db_Adapter_Db2 does not work with iSeries (AS/400)


The reason is the sql statement in the describeTable() method. If you change it to our version, it works. We have created a modified version of Zend_Db_Adapter_Db2 called Zend_Db_Adapter_Db2iseries, that overloads this method, but I think, that some kind of option in Zend_Db_Adapter_Db2 will be better. We are using ZF 1.5.3 now, so it is possible, that it will be necessary to adapt the code for 1.7.x

It seems, that this will not work for z/OS version of DB2, only for AS400

This is our sql code:

    $sql = "SELECT DISTINCT c.table_schema, c.table_name, c.column_name, c.ordinal_position,
          c.data_type, c.column_default, c.is_nullable, c.length, c.numeric_scale,
          c.is_identity, tc.type AS tabconsttype, k.colseq
        FROM qsys2.syscolumns c
          LEFT JOIN (qsys2.syskeys k JOIN qsys2.syscst tc
            ON (k.index_schema = tc.table_schema
              AND k.index_name = tc.table_name
              AND tc.type = 'PRIMARY KEY'))
          ON (c.table_schema = k.index_schema
            AND c.table_name = k.index_name
            AND c.column_name = k.column_name)
          WHERE "
        . $this->quoteInto('UPPER(c.table_name) = UPPER(?)', $tableName);
    if ($schemaName) {
        $sql .= $this->quoteInto(' AND UPPER(c.table_schema) = UPPER(?)', $schemaName);
    $sql .= " ORDER BY c.ordinal_position";


Can't you close this with fix for 1.7.0, Ralph?

Solved in SVN r13093

Satoru, the changes you applied broke unit tests on i5 for OS400 on my v5r4. I am gonna update, then can you test on your i5?

Will keep you posted.


Hi, Ralph. Ok , I will test on my i5 after your commits.

I schedule to work on this in May/2009.

I confirm this issue would not be shown in following test code. This seems to be resolved in 1.7.3 .

class Db2Controller extends Zend_Controller_Action {
    protected $_db;
    public function init() {
        $this->_db = Zend_Db::factory('Db2',
            'host' => '',
            'username' => 'YOUR USER',
            'password' => 'YOUR PASS',
            'dbname'   => 'DSPRDBDIRE VALUE')

    public function indexAction() {
        $result = $this->_db->fetchAll($sql, 'T001');