且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用可变表名创建mysql表

更新时间:2023-02-03 15:45:20

在 SQL 文本中的表名周围使用反引号:

Use backticks around the table name in your SQL text:

mysql_query("CREATE TABLE `$name`(

反引号是 MySQL 中标识符的默认分隔符.(注意:可以启用其他分隔符,但您并不真的想去那里.)

The backticks are the default delimiter for identifiers in MySQL. (Note: it is possible to enable other delimiters, but you don't really want to go there.)

如果标识符是保留字,包含空格等,则反引号是必需的(反引号在很多情况下可以省略,但在不需要时使用它们并没有错.基本上,认为规则为总是在标识符周围使用反引号",并在方便时省略它们并且您确定它们不是必需的.)

The backticks are required if the identifier is a reserved word, contains white space, etc. (The backticks can be omitted in a lot of cases, but it's not wrong to use them when they aren't required. Basically, think of the rule as "always use backticks around identifiers", and omit them when its convenient and you are sure they aren't required.)