I was trying to query a database table by search keyword. My SQL is as follow:
SELECT * FROM some_table WHERE some_name LIKE '%$keyword%'
where $keyword is from PHP form POST data. The $keyword is already processed by real_escape_string function. I notice that it the $keyword is %, all records are selected. How can I search for the some_name field with % in the content?
You have to escape the literal
%, as explained in the manual:EDIT: Also note that you should escape the
_character the same way, as that’s symbol for a single-character wild card.