Welcome Guest, Not a member yet? Register   Sign In
$this->db->like
#5

[eluser]arume[/eluser]
My solution:

Code:
$this->db->where('somefield LIKE '.$this->db->escape($fieldvalue), null, false);

By the way, maybe you must take care to not allow wildcards (in mysql "%" and "_"). Unfortunately CI don't care about that (in the AR LIKE method) nor provide a method to backslash it (as far as I know). So I wrote a function to do it in a mysql_helper.

Code:
function mysql_escape_like($str)
{
  return addcslashes($str, '%_');
}

So, the code will be:

Code:
$this->db->where('somefield LIKE '.mysql_escape_like($this->db->escape($fieldvalue)), null, false);


Messages In This Thread
$this->db->like - by El Forum - 07-15-2008, 05:52 AM
$this->db->like - by El Forum - 07-15-2008, 06:00 AM
$this->db->like - by El Forum - 07-15-2008, 06:19 AM
$this->db->like - by El Forum - 07-15-2008, 07:45 AM
$this->db->like - by El Forum - 07-16-2008, 02:02 AM
$this->db->like - by El Forum - 07-16-2008, 03:30 AM
$this->db->like - by El Forum - 07-16-2008, 03:38 AM
$this->db->like - by El Forum - 07-16-2008, 04:46 AM
$this->db->like - by El Forum - 07-16-2008, 04:55 AM



Theme © iAndrew 2016 - Forum software by © MyBB