I have implemented custom search to get some values from node.
When I'm using special chars like "/, ?, !", no result is being displayed.
Example value : "24/7" or "site?" or "test!", etc...
$search_text = '24/7';
$query->condition(db_or()
->condition('n.title', '%' . db_like($search_text) . '%', 'LIKE')
->condition('fld.body_value', '%' . db_like($search_text) . '%', 'LIKE'));
I'm running my site in Drupal 7. PHP version is 5.5.9. Using Mysql DB. OS windows.
Note: Query is correct. Its giving proper result for other than special chars.
Edit: $query->arguments(); is returning below image.
I was running LIKE command in phpmyadmin. Please find that screen shot below.
So what is the modification do we need to do at PDO to support this issue?
db_like($search_text)
actually returns? See here - that's how you can extract both rendered query, and placeholders. Do it, edit it into your question, and we might be able to help.db_like
is nothing more than sophisticated wrapper aroundaddcslashes
with simple parameters:addcslashes($string, '\%_')
. It shouldn't affect your strings in any way, if it does, we will also need your PHP version and database driver you use with your Drupal. and the data I already requested, of course.db_like('24/7')
returns the string24/7
(as you'd expect), so your problem is somewhere else. Cast the$query
object to a string and see what the SQL is like. That should show you where the problem is