MySQL UDF That does a REGEX Search and Replace

2019-07-15 13:54发布

问题:

Hello I'm a new web developer at open.uwec.edu. I recently had to switch over our web servers and have come across some challenges. Our old MySQL server used a function from the lib_mysqludf_preg library called preg_replace to do regular expression searching and matching. It had some .dlls already compiled in the "MySQL Server 5.1/lib/plugin" folder called lib_mysqludf_preg.dll and libpcre.dll.

If I copy these dlls over to the new server at "MySQL Server 5.6/lib/plugin" and do something like...

CREATE Function preg_replace RETURNS STRING SONAME 'lib_mysqludf_preg.dll';

I get a MySQL 193 format error...

I've looked at the guide on the github repository for this library at https://github.com/mysqludf/lib_mysqludf_preg/blob/testing/doc/INSTALL.windows but the links don't go to the right files like the pcre dll, and it just isn't making sense to me. Is it necessary to compile this preg library from scratch? My function that uses it looks like this.

CREATE DEFINER=`root`@`localhost` FUNCTION `slug`(dirty_string varchar(255)) RETURNS varchar(255) CHARSET latin1
    DETERMINISTIC
BEGIN
    Declare temp_string VarChar(255);
    Set temp_string = replace(dirty_string, '&', ' and ');
    Set temp_string = replace(temp_string, '''', '');
    Set temp_string = preg_replace('/[^a-z0-9-]+/i', '-', temp_string);
    Set temp_string = preg_replace('/^-+|-+$/', '', temp_string);
    Return LOWER(temp_string);
END

Our site makes use of the php codeigniter framework. I have little experience with UDFS on MySQL so I hope I provided enough information. Thank you.