Tuesday, 27 August 2013

Codeigniter, Activerecord and MySQL UDFs

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?

No comments:

Post a Comment