开发者

Mysql syntax error during an update but code look fine

开发者 https://www.devze.com 2023-04-06 08:45 出处:网络
I have a strange issue with a Mysql Update and I\'m not sure what is causing it. I suspect something is wrong with the table itself but the field causing the error appears to be defined the same as ot

I have a strange issue with a Mysql Update and I'm not sure what is causing it. I suspect something is wrong with the table itself but the field causing the error appears to be defined the same as other fiel开发者_如何学运维ds in the table. I can recreate the error in phpMyAdmin on the SQL tab and also in php code. I am completely stumped. The fields in the table are defined as follows:

bnumber is INT length=11
bname is VARCHAR length=60 Collation=latin1_swedish_ci
twittername is VARCHAR length=15 Collation=latin1_swedish_ci
desc is VARCHAR length=60 Collation=latin1_swedish_ci

This update statement works:

update tbl1 set bname='myName', twittername='myTweet' where bnumber=1;

this one gives me the error:

update tbl1 set bname='myName', twittername='myTweet', desc='test' where bnumber=1;

the error I get is:

#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 'desc='Main' where bnumber=1' at line 1.

I don't seem to have any issues selecting from the table or inserting to the table. Only update is giving me the error.

I appreciate any help.

Thanks!


desc is a reserved word in MySQL. You must quote it in backticks.


desc is a keyword. Escape it with backticks.

update tbl1 
    set bname='myName', 
        twittername='myTweet', 
        `desc`='test' 
    where bnumber=1;


desc is a reserved word in mysql

http://dev.mysql.com/doc/refman/5.0/en/reserved-words.html

Updated your sql as below and it will work fine;

update tbl1 set bname='myName', twittername='myTweet', `desc`='test'
where bnumber=1;


you cant use desc as a field name. change fieldname to desc1 and try.

desc is for oder by name desc

0

精彩评论

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