CodeIgniter Forums
Looking for simple way to Not escape active record db->like() search string - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Looking for simple way to Not escape active record db->like() search string (/showthread.php?tid=26976)



Looking for simple way to Not escape active record db->like() search string - El Forum - 01-28-2010

[eluser]Monarobase[/eluser]
Hello,

I'm building a search form and want users to be able to search for more than one words...
(The product names could be new-product-name or new product-name or new, pruduct ! name)
Using preg_replace I remove all bad characters and replace the with a wildcard to get something like this :

Code:
$searchfor = 'new%product%name';

I wanted to look for it using :

Code:
if($searchstring != '') $this->db->like('prodname', $searchfor, 'both');

But the wildcard characters are escaped and no products are returned. I was thinking about expanding the active record library but I have noticed that it's in the database folder and not in the library folder. How would I go about doing this ? should I create a MY_DB_active_rec.php in my appications library folder ? Or could you recommend another approach to get the right search results ?

Thanks.


Looking for simple way to Not escape active record db->like() search string - El Forum - 01-28-2010

[eluser]danmontgomery[/eluser]
Use where and pass FALSE as the 3rd parameter to prevent automatic escaping

Code:
$this->db->where('`prodname` LIKE "%new%product%name%"', NULL, FALSE);



Looking for simple way to Not escape active record db->like() search string - El Forum - 01-29-2010

[eluser]Monarobase[/eluser]
Thankyou that solved my problem.