Forum Moderators: coopster

Message Too Old, No Replies

"SHOW TABLES FROM $database" doesn't work with '-'? workaround?

         

carsten888

9:00 am on Apr 4, 2010 (gmt 0)

10+ Year Member



SHOW TABLES FROM '".$database_name."' 

I need to test for the existence of a table in the database. This query works fine as long as there are no - in the database-name.

Is there a workaround so that this script could deal with - in database-names?

rocknbil

8:21 pm on Apr 4, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You don't need to quote it. You quote the data in fields, not field names or db/table names. That might be the problem all by iself.

I don't even know if any of these will work. :-) The first two are most likely.

$query = "SHOW TABLES FROM ".$database_name;

$query = "SHOW TABLES FROM `".$database_name."`";

Note those are backticks, not quotes.

$query = "SHOW TABLES FROM ".mysql_real_escape_string($database_name);

EDIT: ahhh, dupe thread, I hate it when that happens, mods please splice: Duplicate thread [webmasterworld.com]

carsten888

1:44 pm on Apr 6, 2010 (gmt 0)

10+ Year Member



Thank you very much. That was it!