I\'ve written a simple query for searching a keyword in the database.
$keyword = \"keyword sample\";
$keyword = str_replace(\" \", \"%\", $keyword);
$th
Use the escape_like_str() method.
The escape_like_str() method should be used when strings are to be used in LIKE conditions so that LIKE wildcards %, _ in the string are also properly escaped. It cannot automatically add the ESCAPE ! condition for you, and so you’ll have to manually do that.
Hope it helps.
$keyword = "keyword sample";
$sql = "SELECT id FROM table WHERE column LIKE '%" .
$this->db->escape_like_str($keyword)."%' ESCAPE '!'";
Source:- https://www.codeigniter.com/userguide3/database/queries.html