MYSQL query error [duplicate]
Is there something wrong with this code? I'm running MYSQL 5 I keep getting this error:
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 'desc BLOB, review BLOB, url BLOB )'
Here's my query:
mysql_query("CREATE TABLE videos(
id INT NOT NULL AUTO_INCREMENT,
PRIMARY KEY(id),
title VARCHAR(50),
desc BLOB,
review BLOB,
url BLOB
)
") or die(mysql_开发者_JAVA技巧error());
It looks alright to me. At first I thought it was the "BLOB" datatype but then I tried "TEXT" and it still messed up so I'm not quite sure.
desc
is a reserved keyword, you need to escape it:
mysql_query("CREATE TABLE videos(
id INT NOT NULL AUTO_INCREMENT,
PRIMARY KEY(id),
title VARCHAR(50),
`desc` BLOB,
review BLOB,
url BLOB
)
")or die(mysql_error());
For the full list of reserved keywords, see 8.3. Reserved Words
desc
ise reserved keyword for MySQL, you should cover it with backticks:
CREATE TABLE videos (
id INT NOT NULL AUTO_INCREMENT,
`title` VARCHAR(50),
`desc` BLOB,
`review` BLOB,
`url` BLOB,
PRIMARY KEY (`id`)
)
try with:
mysql_query("CREATE TABLE videos(
`id` INT NOT NULL AUTO_INCREMENT,
PRIMARY KEY(id),
`title` VARCHAR(50) NULL,
`desc` BLOB NULL,
`review` BLOB NULL,
`url` BLOB NULL
)
")or die(mysql_error());
精彩评论