Q: Codeigniter, Activerecord and MySQL UDFs We're currently using lib_mysqludf_preg UDFs for regex pattern matching with Codeigniter and Activerecord.  Using the PREG_REPLACE UDF, I was able to strip all non numeric and alphabetic characters with a custom query, Activerecord failed and returned an error result() on a non object
Works:
$query = $this->db->query(sprintf("SELECT * FROM table WHERE PREG_REPLACE('/[^a-zA-Z 0-9]+/' , '', UPPER(first_name)) = '%s' AND PREG_REPLACE('/[^a-zA-Z 0-9]+/' , '', UPPER(last_name)) = '%s'", $first_name, $last_name));

Doesn't work:
$this->db->where("PREG_REPLACE('/[^a-zA-Z 0-9]+/' , '', UPPER(first_name))", $first_name);
$this->db->where("PREG_REPLACE('/[^a-zA-Z 0-9]+/' , '', UPPER(last_name))", $last_name);

$query = $this->db->get('table');

What gives?

A: In this case, it's better to write your own clauses manually as string.
By the way, you could Add a third parameter to the where() method and set it to FALSE to prevent CodeIgniter from protecting your field or table names with backticks:
$this->db->where("PREG_REPLACE('/[^a-zA-Z 0-9]+/' , '', UPPER(first_name)) = '$first_name'", NULL, FALSE);
$this->db->where("PREG_REPLACE('/[^a-zA-Z 0-9]+/' , '', UPPER(last_name)) = '$last_name'", NULL, FALSE);

$query = $this->db->get('table');

