简体   繁体   English

MySQL字段名称冲突

[英]MySQL field name conflict

I have this table with 50 something fields each field contains the corresponding two character state name. 我有这个表有50个字段,每个字段包含相应的两个字符状态名称。 I have this mysql_query when a state is selected 选择状态时,我有这个mysql_query

//$entry is state name abbr. Oregon = OR<br/>
//$cname and $zoneName aren't important.

'UPDATE stateCarriers SET '.$entry.'= 1 WHERE cname="'.$cname.'" AND zone="'.$zoneName.'"'

so I'm having an issue when OR is the $entry since mysql thinks it is the OR operator. 因为mys是认为它是OR运算符,所以当OR$entry时,我遇到了问题。

How do I solve this issue without changing the field name to something else? 如何在不将字段名称更改为其他内容的情况下解决此问题?

Try using the backtick character, eg `field`=1 to delimit the field. 尝试使用反引号字符,例如`field` = 1来分隔字段。 This seems to work pretty well for me, although it was under slightly different circumstances. 这对我来说似乎很有效,尽管情况略有不同。

'UPDATE stateCarriers SET`'。$ entry.'` = 1 WHERE cname =“'。$ cname。'”AND zone =“'。$ zoneName。'”'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM