Version CodeIgniter 3 PHP 5.4
Thanks to the Almighty StackOverflow.
To modify the source code of CodeIgniter.
./system/database/drivers/mysql/mysql_driver.php
/** * Escape String * * @access public * @param String * @param bool whether or not the String would be used-a like condition * @return string*/ functionESCAPE_STR ($str,$like=FALSE) { if(Is_array($str)) { foreach($str as $key=$val) { $str[$key] =$this->ESCAPE_STR ($val,$like); } return $str; } if(function_exists(' mysql_real_escape_string ') andIs_resource($this-conn_id)) { $str=mysql_real_escape_string($str,$this-conn_id); } ElseIf(function_exists(' mysql_real_escape_string ')) { if(Is_object($this-conn_id)) { $str=mysql_real_escape_string($str,$this-conn_id); } Else { $str=addslashes($str); } }ElseIf(function_exists(' mysql_escape_string ')) { $str=mysql_escape_string($str); } Else { $str=addslashes($str); } //escape like condition wildcards if($like===TRUE) { $str=Str_replace(Array(‘%‘, ‘_‘),Array(‘\\%‘, ‘\\_‘),$str); } return $str; }
Italic underlined is the modified part.
Reference: https://stackoverflow.com/questions/33995279/ codeigniter-showing-error-mysql-real-escape-string-expects-parameter-2-to-be
Php:codeigniter mysql_real_escape_string Warning