php + unixODBC + DB2 + DESCRIBE = token not valid?
Asked Answered
D

4

1

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?

Drinkwater answered 30/9, 2008 at 16:41 Comment(0)
M
6

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'
Mcvey answered 8/10, 2008 at 19:34 Comment(1)
Thank you so much for this example. Do you happen to know how to get field descriptions as well?Ignacioignacius
F
1

This statement can only be embedded in an application program. It is an executable statement that cannot be dynamically prepared. It must not be specified in Java.

From the iSeries DB2 SQL Reference.

Flighty answered 3/11, 2008 at 20:32 Comment(0)
A
0

To me it looks like you need to provide a way for the statement to return a value "Valid tokens: INTO" tells me that. I haven't used DESCRIBE before, but I would imagine that it returns something.

Interactive SQL doesn't allow the command so I can't really help you much further than that.

BTW, add the iSeries tag to your question. You might get a few more answers that way.

Anatto answered 30/9, 2008 at 17:48 Comment(0)
R
0

If you just need the column names try

select * from <TABLE> where 0 = 1

I don't know how to get the column types, indexes, keys, &c

Royalroyalist answered 6/10, 2008 at 10:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.