8

I am trying to drop a table in a database with the following query statement:

mysql_query('DROP TABLE IF EXISTS "dbName.tableName"') or die(mysql_error());

But I keep getting an error. Does anyone know if specifying the dbName.tableName is invalid?

Kara
  • 6,115
  • 16
  • 50
  • 57
H. Ferrence
  • 7,906
  • 31
  • 98
  • 161

3 Answers3

21
mysql_query('DROP TABLE IF EXISTS `dbName`.`tableName`') or die(mysql_error());
Emmerman
  • 2,371
  • 15
  • 9
6

You should use backticks instead of double quotes like this:

mysql_query('DROP TABLE IF EXISTS `dbName`.`tableName`');
Kris
  • 2,108
  • 18
  • 19
  • 1
    There where two problems with your original code. First, you should quote the dbName and tableName separately. Second, you only use single- or double quotes for strings. For identifiers, like table and column names, you use the backtick: http://dev.mysql.com/doc/refman/5.0/en/identifiers.html – Kris May 18 '11 at 14:52
3

You can't use double quotes to quote db/table names, instead you either leave them unquoted or use backticks. But to answer your question, yes it is perfectly valid to specify the database name.

DROP TABLE `dbName`.`tableName`
John Cartwright
  • 5,109
  • 22
  • 25