0

I'm trying to execute the following:

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)

But because one of columns have quotation mark in name ( 083FUNKTIONSKRAVLJUDISOLERINGKlassR\'wdB ) I'm getting this error:

#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

Any idea or suggestions will be appreciated.

Common MySQL guru's.

Haris Hajdarevic
  • 1,535
  • 2
  • 25
  • 39

1 Answers1

1

Short: don't do this.

Longer: you can use the backtick ` to quote column names:

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

to use them in PHP, put that in between single or double quotes:

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

or

$key = "`$key`"
Bart Friederichs
  • 33,050
  • 15
  • 95
  • 195
  • Yes, I know how that is working but I don't know how to add backticks in PHP to variable. They somehow disappear when I try something like this $key = ` . $key . `; – Haris Hajdarevic Dec 01 '14 at 15:51
  • @PottaG just put them inside the string. In PHP the backtick has no special meaning. See my updated answer. – Bart Friederichs Dec 01 '14 at 15:54