Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

escape single quotes

Tags:

mysql

I have a table like this...

select * from myescape;
+-----------+
| name      |
+-----------+
| shantanu' |
| kumar's   |
+-----------+
2 rows in set (0.00 sec)

I need to replace the single quote ' with \'

I will also need to escape double quotes and backslash.

like image 812
shantanuo Avatar asked Sep 04 '10 12:09

shantanuo


1 Answers

The point of prepared statements is that you don't have to include content in them. Use a PREPARE query with ? placeholders and then EXECUTE ... USING to pass the values in without having to escape them.

Don't try to do escaping yourself, because you're likely to make mistakes. Depending on what encoding you're using, there can be more to it than just backslash-escaping quotes, backslash and null.

like image 190
bobince Avatar answered Oct 05 '22 09:10

bobince