2012-11-19 49 views
0

我對此查詢有問題。MySQL查詢錯誤(使用php)

$query = 'CREATE TABLE movie(
    movie_id UNSIGNED INTEGER NOT NULL AUTO_INCREMENT, 
    movie_name VARCHAR(255) NOT NULL, 
    movie_type TINYINT NOT NULL DEFAULT 0, 
    movie_year SMALLINT UNSIGNED NOT NULL DEFAULT 0, 
    movie_leadactor INTEGER UNSIGNED NOT NULL DEFAULT 0, 
    movie_director INTEGER UNSIGNED NOT NULL DEFAULT 0, 

    PRIMARY KEY (movie_id), 
    KEY movie_type (movie_type, movie_year) 
    ) 
    ENGINE=MyISAM'; 
$result = mysql_query($query, $db) or die(mysql_error($db)); 

它仍然這樣寫:

您的SQL語法錯誤;檢查對應於你的MySQL服務器版本正確的語法附近使用手冊「無符號整數NOT NULL AUTO_INCREMENT,MOVIE_NAME VARCHAR(255)NOT NULL,」在第2行

回答

3

無符號必須在int後面出現。我重寫了您的查詢並驗證了它現在可以正常工作。

CREATE TABLE movie(
movie_id INT UNSIGNED NOT NULL AUTO_INCREMENT, 
movie_name VARCHAR(255) NOT NULL, 
movie_type TINYINT NOT NULL DEFAULT 0, 
movie_year SMALLINT UNSIGNED NOT NULL DEFAULT 0, 
movie_leadactor INT UNSIGNED NOT NULL DEFAULT 0, 
movie_director INT UNSIGNED NOT NULL DEFAULT 0, 
PRIMARY KEY (movie_id), 
KEY movie_type (movie_type, movie_year) 
) 
ENGINE=MyISAM 
0

MySQL的整數類型稱爲INT,不INTEGER

0

試試這個,你INTEGER可寫爲INT,你把無符號的變量在它之前,它需要去後 -

$query = 'CREATE TABLE movie(
`movie_id` INT UNSIGNED NOT NULL AUTO_INCREMENT, 
`movie_name` VARCHAR(255) NOT NULL, 
`movie_type` TINYINT NOT NULL DEFAULT 0, 
`movie_year` SMALLINT UNSIGNED NOT NULL DEFAULT 0, 
`movie_leadactor` INTEGER UNSIGNED NOT NULL DEFAULT 0, 
`movie_director` INTEGER UNSIGNED NOT NULL DEFAULT 0, 

PRIMARY KEY (movie_id), 
KEY movie_type (movie_type, movie_year) 
) 
ENGINE=MyISAM'; 
$result = mysql_query($query, $db) or die(mysql_error($db));