Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/250.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用数据值tinytext、longtext和enum创建表时出现MySQL语法错误_Php_Mysql - Fatal编程技术网

Php 使用数据值tinytext、longtext和enum创建表时出现MySQL语法错误

Php 使用数据值tinytext、longtext和enum创建表时出现MySQL语法错误,php,mysql,Php,Mysql,我的代码如下: $sql = " CREATE TABLE articles ( articleUID int NOT NULL AUTO_INCREMENT, PRIMARY KEY(articleUID), by tinytext, article longtext, game enum('Starcraft','Starcraft 2','Team Fortress 2','Minecraft'

我的代码如下:

$sql = "
    CREATE TABLE articles (
        articleUID int NOT NULL AUTO_INCREMENT, 
        PRIMARY KEY(articleUID), 
        by tinytext, 
        article longtext, 
        game enum('Starcraft','Starcraft 2','Team Fortress 2','Minecraft','Tekkit','other')
    )
";
if(mysql_query($sql, $con)) {
    echo "The table \"articles\" was created succesfully.<br />";
} else{
    echo "Error creating  table: " . mysql_error() . "<br />";
}
我不知道你是否需要我剩下的代码来解决这个问题,但是如果你需要,我会在编辑中发布它。谁能告诉我这里怎么了?我尝试过在枚举参数上使用“代替”,但这不起作用。

BY
是一个参数,当用作列或表标识符时,必须用反勾号引用

您可以在列定义的右侧声明主键:

$sql = "CREATE TABLE articles (
  articleUID int NOT NULL AUTO_INCREMENT PRIMARY KEY,
  /* Quote the reserved word BY */
  `by` tinytext, 
  article longtext, 
  game enum('Starcraft','Starcraft 2','Team Fortress 2','Minecraft','Tekkit','other')
)";
或者,您可以在列定义之后使用括号声明
主键

$sql = "CREATE TABLE articles (
  articleUID int NOT NULL AUTO_INCREMENT,
  `by` tinytext, 
  article longtext, 
  game enum('Starcraft','Starcraft 2','Team Fortress 2','Minecraft','Tekkit','other'),
  PRIMARY KEY (articleUID)
)";
BY
是一个标识符,当用作列或表标识符时,必须用反勾号引用

您可以在列定义的右侧声明主键:

$sql = "CREATE TABLE articles (
  articleUID int NOT NULL AUTO_INCREMENT PRIMARY KEY,
  /* Quote the reserved word BY */
  `by` tinytext, 
  article longtext, 
  game enum('Starcraft','Starcraft 2','Team Fortress 2','Minecraft','Tekkit','other')
)";
或者,您可以在列定义之后使用括号声明
主键

$sql = "CREATE TABLE articles (
  articleUID int NOT NULL AUTO_INCREMENT,
  `by` tinytext, 
  article longtext, 
  game enum('Starcraft','Starcraft 2','Team Fortress 2','Minecraft','Tekkit','other'),
  PRIMARY KEY (articleUID)
)";

您已将主键定义放在列定义之间。首先声明所有列,然后在末尾声明主键。

您已将主键定义放在列定义之间。首先声明所有列,然后在末尾声明主键。

by
是mysql中的关键字。如果不要将其用作关键字,请将其引用。此外,在定义自动递增和主键时,您也有一个错误

$sql = "CREATE TABLE articles (
    `articleUID` int NOT NULL AUTO_INCREMENT PRIMARY KEY,
    `by` tinytext, 
    `article longtext,
    `game` enum('Starcraft','Starcraft 2','Team Fortress 2','Minecraft','Tekkit','other')
)";

by
是mysql中的一个关键字。如果您不想将其用作关键字,请将其引用。此外,在定义自动递增和主键时,您也有一个错误

$sql = "CREATE TABLE articles (
    `articleUID` int NOT NULL AUTO_INCREMENT PRIMARY KEY,
    `by` tinytext, 
    `article longtext,
    `game` enum('Starcraft','Starcraft 2','Team Fortress 2','Minecraft','Tekkit','other')
)";