1064 SQL create table错误

时间:2014-08-18 12:25:34

标签: php sql

1064:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''models'( 'model_id' INT NOT NULL AUTO_INCREMENT PRIMARY KEY, 'model_usernam' at line 1

当我尝试创建sql表时出现此错误。

这是代码..请帮忙..

$sql = "CREATE TABLE IF NOT EXISTS 'models'(
    'model_id' INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
    'model_username' VARCHAR(250) NOT NULL,
    'model_gender' ENUM('f','m','s','c') NOT NULL,
    'model_show' ENUM('public','private','group','away') NOT NULL,
    'model_age' INT NOT NULL,
    'model_time' INT NOT NULL,
    'model_new' TINYINT(1) NOT NULL default '0',
    'model_hd' TINYINT(1) NOT NULL default '0',
    'model_recorded' TINYINT(1) NOT NULL default '0',
    'model_image' VARCHAR(250) NOT NULL,
    'model_users' INT NOT NULL,
    'model_language' VARCHAR(250),
    'model_name' VARCHAR(250),
    'model_location' VARCHAR(250),
    'model_subject' VARCHAR(250),
    'model_roomurl' VARCHAR(250) NOT NULL,
    'model_roomurlrevshre' VARCHAR(250) NOT NULL,
    'model_iframe' VARCHAR(250) NOT NULL,
    'model_iframerevshre' VARCHAR(250) NOT NULL,
    'model_birthday' VARCHAR(250) NOT NULL )";

2 个答案:

答案 0 :(得分:7)

使用反引号作为列名而不是单引号。

$sql = "CREATE TABLE IF NOT EXISTS `models`(
`model_id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
`model_username` VARCHAR(250) NOT NULL,
`model_gender` ENUM('f','m','s','c') NOT NULL,
`model_show` ENUM('public','private','group','away') NOT NULL,
`model_age` INT NOT NULL, ...

答案 1 :(得分:0)

尝试这个我刚试过它,它的工作原理。它是反引号和单引号的问题

CREATE TABLE IF NOT EXISTS `models`(
    model_id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
    model_username VARCHAR(250) NOT NULL,
    model_gender ENUM('f','m','s','c') NOT NULL,
    model_show ENUM('public','private','group','away') NOT NULL,
    model_age INT NOT NULL,
    model_time INT NOT NULL,
    model_new TINYINT(1) NOT NULL default 0,
    model_hd TINYINT(1) NOT NULL default 0,
    model_recorded TINYINT(1) NOT NULL default 0,
    model_image VARCHAR(250) NOT NULL,
    model_users INT NOT NULL,
    model_language VARCHAR(250),
    model_name VARCHAR(250),
    model_location VARCHAR(250),
    model_subject VARCHAR(250),
    model_roomurl VARCHAR(250) NOT NULL,
    model_roomurlrevshre VARCHAR(250) NOT NULL,
    model_iframe VARCHAR(250) NOT NULL,
    model_iframerevshre VARCHAR(250) NOT NULL,
    model_birthday VARCHAR(250) NOT NULL );