Hi, I'm trying to update a row of text which contains escaped characters (apostrophies) For example, with this in the database table: I like shopping. it is my hobby. Code (markup): The following SQL statement works fine: update mytable set myfield = 'abc' where myfield = 'I like shopping. it is my hobby.' Code (markup): Whereas with the following in the database table: I like shopping. it\'s my hobby. Code (markup): The following SQL statement makes no replacement! update mytable set myfield = 'abc' where myfield = 'I like shopping. it\'s my hobby.' Code (markup): Why is this? Also, I cannot replace based on the primary key, as the table may not have one! It must be based on the text field!
I wouldn't be surprised if there was a built in feature to cope with accidentally entered apostrophes, but if there is I do not know of it. A less clean solution that should work however would be: update mytable set myfield = 'abc' where myfield LIKE 'I like shopping. it%s my hobby.' Code (markup):
Thanks, but wouldn't that also match up to the following?: 'I like shopping. it is ok. and fishing is my hobby.' Code (markup):
Sorted it! The MySQL software I was using (Navicat) Was hiding the backslashes from me. It turns out I had double-slashed stuff!
god this anti spam crap is annoying... php dot net/manual/en/function.mysql-real-escape-string.php <-- the solution is here