Welcome to WebmasterWorld Guest from 54.242.231.210

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

PHP/ODBC Query problem

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

Senior Member

WebmasterWorld Senior Member 5+ Year Member

joined:May 6, 2008
posts:2011
votes: 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...
3:16 pm on Apr 14, 2010 (gmt 0)

New User

5+ Year Member

joined:Nov 30, 2009
posts: 37
votes: 0


just curious, you have a table in your database named "table_name"?
3:30 pm on Apr 14, 2010 (gmt 0)

Senior Member

WebmasterWorld Senior Member 5+ Year Member

joined:May 6, 2008
posts:2011
votes: 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.
3:45 pm on Apr 14, 2010 (gmt 0)

New User

5+ Year Member

joined:Nov 30, 2009
posts:37
votes: 0


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

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members