Php + unixODBC + DB2 + DESCRIBE = token not valid

db2db2-400ibm-midrangePHPunixodbc

Code I am trying to run:

$query = "DESCRIBE TABLE TABLENAME";
$result = odbc_exec($h, $query);

The result:

PHP Warning: odbc_exec(): SQL error: [unixODBC][IBM][iSeries Access
ODBC Driver][DB2 UDB]SQL0104 – Token TABLENAME was not valid. Valid
tokens: INTO., SQL state 37000 in SQLExecDirect in …

There were no other problems with SELECT, INSERT, UPDATE or DELETE queries on the same connection. Is this a syntax error?

Best Answer

The iSeries flavor of DB2 does not support the SQL DESCRIBE statement. Instead, you have to query the system table:

select * from qsys2.columns where table_schema = 'my_schema' and table_name = 'my_table'
Related Topic