I have a field in one of my tables that contains this string:
!"#¤%&/()=?´`?=)(/&%¤#"!\'\'"'
(Only for test purposes ofcourse). I've tried endless of queries to properly select this field, and without returning any errors of course, but I just can't seem to get it right.
This is the query I'm using currently:
SELECT * FROM mytable WHERE `column` LIKE '%!"#¤%&/()=?´`?=)(/&%¤#"!\\\'\\\'"\'%'
Can anyone shed some light on what it is I'm not doing right? Are there any other characters (other than '
) that I should escape? I haven't read about it anywhere... (I did however try adding backslashes before the precent symbols).
Are you using PHP? If so, you may try something like:
Would that solve your problem?
From MySQL Manual:
So, you should escape string for
LIKE
operator in two steps.In PHP it can be like this:
UPDATE:
Use MySQLi
Use PDO
Or you can use PDO prepared statement, instead of second step (literal escaping):
Is not clear what you are trying to obtain and what is going wrong.
By the way, if you want to protect your query from SQL injection you should use mysql_real_escape_string
http://dev.mysql.com/doc/refman/5.0/en/mysql-real-escape-string.html
Assuming that you are in PHP
But you have to remember that LIKE operator has his own special chars (wildchars)
http://dev.mysql.com/doc/refman/5.0/en/string-comparison-functions.html#operator_like
So this chars must be escaped with backslash if you want to stop their magic
Assuming that you are in PHP I would do