Last active
June 18, 2021 08:26
-
-
Save serkanalgur/19f53dd99a250825d34a1f0018858c81 to your computer and use it in GitHub Desktop.
json_extract and json_unquote creator functions for Mysql < 5.7 . If you use translatable texts with Laravel you can use this. (I was forced to use Laravel with cPanel built with MySQL 5.6)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DELIMITER $$ | |
CREATE FUNCTION `json_extract`(`details` TEXT, `required_field` VARCHAR(255)) RETURNS text CHARSET utf8mb4 | |
BEGIN | |
RETURN TRIM( | |
BOTH '"' FROM SUBSTRING_INDEX( | |
SUBSTRING_INDEX( | |
SUBSTRING_INDEX( | |
details, | |
CONCAT( | |
'"', | |
SUBSTRING_INDEX(required_field,'$.', - 1), | |
'"' | |
), | |
- 1 | |
), | |
'",', | |
1 | |
), | |
':', | |
- 1 | |
) | |
) ; | |
END$$ | |
DELIMITER ; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DELIMITER $$ | |
CREATE FUNCTION `json_unquote`(`mdata` TEXT CHARSET utf8mb4) RETURNS text CHARSET utf8mb4 | |
BEGIN | |
RETURN mdata; | |
END$$ | |
DELIMITER ; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
json_extract
andjson_unquote
creator functions for Mysql < 5.7 . If you use translatable texts with Laravel you can use this. (I was forced to use Laravel with cPanel built with MySQL 5.6)