列名称中的单引号

时间:2014-12-01 15:44:42

标签: mysql

我试图执行以下操作:

UPDATE door_instances SET pt_id = '9906662', 0221RUMSNUMMER = 'C0962', 0311HNGNINGHV = 'V', 0312Angreppssida = 'Gångjärnssida', 083FUNKTIONSKRAVLJUDISOLERINGKlassR\'wdB = '30', 131KARMVGGTJOCKLEK = '145', ingrejirapport = 'Nej', isFinished = 'Nej', isNew = 'Nej', 211FRKLARINGAROCHFRESKRIFTER = '', 212GRNSDRAGNING = '', 213KANALISATIONDRRMILJ = '', 215RITNINGAR = '', 216DETALJER = '', 214BESKRIVNINGAR = '' WHERE id IN (105239)

但由于其中一列的名称中有引号(083FUNKTIONSKRAVLJUDISOLERINGKlassR \' wdB),我收到此错误:

#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 '\'wdB = '30', 131KARMVGGTJOCKLEK = '145', ingrejirapport = 'Nej', isFinished = '' at line 1

任何想法或建议将不胜感激。

常见的MySQL大师。

1 个答案:

答案 0 :(得分:1)

简短:不要这样做。

更长:您可以使用反引号`来引用列名:

...da', `083FUNKTIONSKRAVLJUDISOLERINGKlassR'wdB` = '30', 131KARMVG...

在PHP中使用它们,将它放在单引号或双引号之间:

$key = '`'.$key.'`'

$key = "`$key`"