Question

I want to add mysql function:

CREATE FUNCTION `chf_get_translation`(translation_id INT, site_lang INT) 
RETURNS text CHARSET utf8
BEGIN

  DECLARE translation TEXT;

  SELECT title 
    INTO translation 
    FROM chf_translations 
   WHERE key_id = translation_id 
     AND lang_id = site_lang;

  RETURN translation;

END

But get error:

1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 3

Was it helpful?

Solution

Try...

DELIMITER $$

CREATE FUNCTION `chf_get_translation`(translation_id INT, site_lang INT) 
RETURNS text CHARSET utf8
BEGIN

  DECLARE translation TEXT;

  SELECT title 
    INTO translation 
    FROM chf_translations 
   WHERE key_id = translation_id 
     AND lang_id = site_lang;

  RETURN translation;

END$$

OTHER TIPS

DELIMITER $

CREATE FUNCTION `chf_get_translation`(translation_id INT, site_lang INT) 
RETURNS text CHARSET utf8
DETERMINISTIC
BEGIN

  DECLARE translation TEXT;

  SELECT title 
    INTO translation 
    FROM chf_translations 
   WHERE key_id = translation_id 
     AND lang_id = site_lang;

  RETURN translation;

END$
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top