Just go it working. It seems that the DELIMTER statement is only for the MySQL commandline. I now simply have this ($this->db->query() is my code):
Code: Select all
$this->db->query('CREATE FUNCTION is_invalid_utf8(s BLOB)
RETURNS int
DETERMINISTIC
BEGIN
DECLARE i INT DEFAULT 1;
DECLARE c INT;
DECLARE num_expected_highs INT DEFAULT 0;
WHILE (i <= length(s)) DO
SET c = ord(mid(s, i, 1));
IF num_expected_highs > 0 THEN
IF (c & 192)<>128 THEN
RETURN 1;
END IF;
SET num_expected_highs = num_expected_highs - 1;
ELSE
IF (c & 224) = 192 THEN
SET num_expected_highs = 1;
ELSEIF (c & 240) = 224 THEN
SET num_expected_highs = 2;
ELSEIF (c & 248) = 240 THEN
SET num_expected_highs = 3;
ELSEIF (c & 128 = 128) THEN
RETURN 1;
END IF;
END IF;
SET i = (i+1);
END WHILE;
RETURN num_expected_highs;
END');I've never used a stored procedure before. Is it normally so slow? Testing with and without there's a difference of 0.6 seconds (a total PHP script run of 0.2 to 0.8 seconds). Other than that, I'm pretty satisfied that the problem I started off with on this thread has now been solved. Thank you very, very much for your help and patience.