redconservatory redconservatory - 11 months ago 38
SQL Question

MySQL SELECT * WHERE name = "something with a backslash \"

I have a table

table_id | name | amount
1 | Arby\'s| 12
2 | Wendy's| 8

I usually do a

SELECT * WHERE table_id = whatever

But I would like (instead) do:

SELECT * WHERE name = "Arby\'s";

However, I seem to be running into problems with the backslash. The result isn't showing up at all. I've also tried

SELECT * WHERE name = 'Arby's;

Without any luck.

Is there any way to search by name if the name contains apostrophes or other special characters (ampersands etc?)


If you're on PHP, you can use mysql_real_escape_string()

You might also want to look at this how to escape special character in mysql