SQL语法中的错误检查与MySQL服务器版本对应的手册

时间:2014-01-08 18:09:10

标签: php mysql sql

 CREATE TABLE `mytable` (
`cid` TINYINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`ckey` TINYTEXT UNSIGNED NOT NULL ,
`cdate` TINYTEXT UNSIGNED NOT NULL ,
`ctime` TINYTEXT UNSIGNED NOT NULL ,
`cuser` TINYTEXT UNSIGNED NOT NULL ,
`ctext` LONGTEXT UNSIGNED NOT NULL ,
`cstatus` TINYTEXT UNSIGNED NOT NULL
) ENGINE = MYISAM CHARACTER SET utf8 COLLATE utf8_general_ci
MySQL说:

  

1064 - 您的SQL语法出错;查看与您的MySQL服务器版本相对应的手册,以便在第1行使用“UNSIGNED NOT NULL,cdate TINYTEXT UNSIGNED NOT NULL,ctime TINYTEXT UNSIGNED”附近使用正确的语法

更新了完整代码:

$query = "
CREATE TABLE mytable (
  cid INT(1) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
  ckey TINYTEXT(10) NOT NULL ,
  cdate TINYTEXT(10) NOT NULL ,
  ctime TINYTEXT(10) NOT NULL ,
  cuser TINYTEXT(10) NOT NULL ,
  ctext LONGTEXT(10) NOT NULL ,
  cstatus TINYTEXT(10) NOT NULL
 ) ENGINE = MYISAM CHARACTER SET utf8 COLLATE utf8_general_ci AUTO_INCREMENT = 1;";

2 个答案:

答案 0 :(得分:0)

您必须指定字符串最大长度,例如:

CREATE TABLE `mytable` (
`cid` TINYINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`ckey` TINYTEXT(10) UNSIGNED NOT NULL ,
`cdate` TINYTEXT(10) UNSIGNED NOT NULL ,
`ctime` TINYTEXT(10) UNSIGNED NOT NULL ,
`cuser` TINYTEXT(10) UNSIGNED NOT NULL ,
`ctext` LONGTEXT(10) UNSIGNED NOT NULL ,
`cstatus` TINYTEXT(10) UNSIGNED NOT NULL
) ENGINE = MYISAM CHARACTER SET utf8 COLLATE utf8_general_ci

其中10是你的价值。希望有用

答案 1 :(得分:0)

我不知道它是否回答了这个问题,因为我尝试通过php而且它没有工作所以我直接做了

CREATE TABLE `mytable` (
`cid` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`ckey` TINYTEXT NOT NULL ,
`cdate` TINYTEXT NOT NULL ,
`ctime` TINYTEXT NOT NULL ,
`cuser` TINYTEXT NOT NULL ,
`ctext` TEXT NOT NULL ,
`cstatus` TINYINT UNSIGNED NOT NULL
) ENGINE = MYISAM CHARACTER SET utf8 COLLATE utf8_general_ci;