views:

237

answers:

2

Hi, I currently have the following MySQL statement to replace the HTML entity for a single quote with an actual single quote:

update photo_galleries replace(title, ''', '\'');

This statement returns an error. I have tried adding additional backslashes, but this does not help at all. I want to run this command using pure SQL (no PHP, etc.). Any suggestions are welcome and appreciated. Thanks.

+1  A: 

This isn't a valid SQL query, you were probably looking for:

UPDATE photo_galleries
SET title = REPLACE(title, ''', '\'');
Chad Birch
That is exactly what I meant - I accidentally excised the missing part. Oops - and thanks!
modulaaron
@modulaaron: You mean that this still returns an error?
Daniel Vassallo
No, works great. I previously had unintentionally removed the "SET title = " from the statement and did not notice.
modulaaron
@modulaaron: You may want to mark the answer as accepted, by clicking on the green tick, if it was helpful. And welcome to Stack Overflow :)
Daniel Vassallo
+2  A: 

Your UPDATE statement is invalid. You may want to try:

UPDATE photo_galleries SET title = REPLACE(title, ''', '\'');

The REPLACE() function works correctly:

SELECT REPLACE('hello='test'', ''', '\'') AS output;
+--------------+
| output       |
+--------------+
| hello='test' | 
+--------------+
1 row in set (0.00 sec)
Daniel Vassallo
Problem already solved but good to know - thanks.
modulaaron