Can you DROP TABLE IF EXISTS by specifying databas

2019-03-26 02:54发布

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?

3条回答
叛逆
2楼-- · 2019-03-26 03:33

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`
查看更多
叼着烟拽天下
3楼-- · 2019-03-26 03:50
mysql_query('DROP TABLE IF EXISTS `dbName`.`tableName`') or die(mysql_error());
查看更多
姐就是有狂的资本
4楼-- · 2019-03-26 03:56

You should use backticks instead of double quotes like this:

mysql_query('DROP TABLE IF EXISTS `dbName`.`tableName`');
查看更多
登录 后发表回答