开发者

MYSQL query error [duplicate]

This question already has an answer here: Syntax error due to using a reserved word as a table or column name in MySQL (1 answer) Closed 8 years ago.

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());
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜