phpcodeigniterescapingsql-likequoting

How to write two LIKE conditions separated by OR inside of parentheses with CodeIgniter


I use CI3 and I have a problem using escape() in LIKE conditions. Here is my code :

$where = '(a.title LIKE \'%'. $this->db->escape($name) .'%\' OR agi.senior_artist LIKE \'%'. $this->db->escape($name) .'%\')'

The problem is $this->db->escape() adds quotes to the string, so I got an error. It works without the escape(), and only $name but I prefer to escape the data.

Is there a native solution?


Solution

  • You need to use

    $this->db->escape_like_str()
    

    instead

    $this->db->escape()
    

    when you use LIKE conditions

    Read more