Saturday, April 13, 2013

reserved keywords in mysql

today,  I created 3 mysql tables for my facebook app, to save user "status" "comment" "like" infomation.

I did not think too much before i created the 3 tables with name: status, comment, like respectively.
then, I found I could insert content into status and comment table while always failed the like table .

/*php code*/
mysql_query("INSERT INTO like (object_id,user_id,type) VALUES ('$comment_id', '$like_user_id','comment')");//error

I did know the 'like' is one mysql reserved keyword, however, i did not think that way at that very moment

then when I changed the table name from 'like' to 'likes', then it works.
/*php code*/
mysql_query("INSERT INTO likes (object_id,user_id,type) VALUES ('$comment_id', '$like_user_id','comment')");//correct //or mysql_query("INSERT INTO my_like (object_id,user_id,type) VALUES ('$comment_id', '$like_user_id','comment')");//correct
Here is the official mysql reserved keyword.
http://dev.mysql.com/doc/refman/5.0/en/reserved-words.html

however, I think it's safe to name your table or column as: my_xxx.

No comments:

Post a Comment