homepage Welcome to WebmasterWorld Guest from 54.211.7.174
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
PHP/ODBC Query problem
StoutFiles




msg:4115740
 2:53 pm on Apr 14, 2010 (gmt 0)

Using a ODBC driver to connect to a database.

Connection works ok:

$db = odbc_connect( 'database','username','password');


View all tables in database works ok:

$result = odbc_tables($db);
$tables = array();
while (odbc_fetch_row($result))
{
if(odbc_result($result,"TABLE_TYPE")=="TABLE")
echo"<br>".odbc_result($result,"TABLE_NAME");
}


View all columns in table works ok:

$result = odbc_columns($db, "database", "", "table_name", "%");
while (odbc_fetch_row($result)) {
echo odbc_result_all($result);
}


However, when I try to make a query of my own it complains about the table name.

$result = odbc_exec($db, "SELECT * FROM table_name");


Warning: odbc_exec() [function.odbc-exec]: SQL error: [IBM][CLI Driver][DB2/AIX64] SQL0204N "username.table_name" is an undefined name. SQLSTATE=42704 , SQL state S0002

Anyone encountered this problem before? My only theory is that it's looking for username.table_name instead of table_name...

 

ENetArch




msg:4115759
 3:16 pm on Apr 14, 2010 (gmt 0)

just curious, you have a table in your database named "table_name"?

StoutFiles




msg:4115770
 3:30 pm on Apr 14, 2010 (gmt 0)

^No, just makes it easier to explain that way.

Figured out the problem though.

If a table was called AREA_BLUE when I did a show tables it was only listed as BLUE. Therefore, in my query I had to use AREA.BLUE as the table name. It was confusing because I don't control these tables.

ENetArch




msg:4115771
 3:45 pm on Apr 14, 2010 (gmt 0)

glad you figured it out =) good luck with the rest of your project. =)

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved