I have a mySql dB with single quotes and other special html charaacters in my data set.
How can i convert these char's into special characters like &
(ampersand) becomes &
?
PHP has htmlspecialchars
, is there a SQL command that allows me to do this or would i have to create a new table using PHP?
This would be for a 1 time conversion, not on every look up.
Asked
Active
Viewed 71 times
0

t q
- 4,593
- 8
- 56
- 91
-
3Why do you want it in SQL, not PHP? – Your Common Sense Aug 14 '13 at 15:00
-
i have lots of rows and thought sql would be more direct – t q Aug 14 '13 at 15:01
-
You will have to implement probably stored function for that purpose. Build-in, no there isn't, since SQL has nothing to do with HTML (nothing in common). And yes, not a good idea, will load DB with useless stuff to do. – Rolice Aug 14 '13 at 15:01
-
1Convert your text to HTML only when you put it in an HTML document. Don't store HTML in the database. – Quentin Aug 14 '13 at 15:02
-
2You are having an extremely bad idea. Do it in PHP, not SQL. – N.B. Aug 14 '13 at 15:02
-
If you're piping the output through PHP anyway, it's better to put work on the PHP side than the database side. You could add another web server easily, but another database is _much_ harder. Also, PHP as you say has an existing, optimized function for it, MySQL does not. – Joachim Isaksson Aug 14 '13 at 15:02
-
if you do it in sql, it will put more load database - replacing all fetched characters with new character. I suggest you do it in php end. – Abani Meher Aug 14 '13 at 15:02
-
1Here is something you can use http://stackoverflow.com/questions/2627940/remove-html-tags-from-record – JTC Aug 14 '13 at 15:06
-
so keep the single quotes in the table and when i output deal with it in php? – t q Aug 14 '13 at 15:06
1 Answers
0
So keep the single quotes in the table and when output, deal with them in PHP, using htmlspecialchars()

Your Common Sense
- 156,878
- 40
- 214
- 345