php 您可以通过在表中指定数据库名称来 DROP TABLE IF EXISTS 吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6046474/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 23:12:02  来源:igfitidea点击:

Can you DROP TABLE IF EXISTS by specifying database name with table?

phpmysqlsql-drop

提问by H. Ferrence

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?

但我不断收到错误消息。有谁知道指定 dbName.tableName 是否无效?

回答by Emmerman

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

回答by Kris

You should use backticks instead of double quotes like this:

您应该使用反引号而不是像这样的双引号:

mysql_query('DROP TABLE IF EXISTS `dbName`.`tableName`');

回答by John Cartwright

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.

您不能使用双引号来引用 db/table 名称,而是将它们不加引号或使用反引号。但是要回答您的问题,是的,指定数据库名称是完全有效的。

DROP TABLE `dbName`.`tableName`