scarhand Posted October 3, 2009 Share Posted October 3, 2009 i have this code: DELIMITER $$ CREATE FUNCTION LAT_LNG_DISTANCE(lat1 FLOAT, lng1 FLOAT, lat2 FLOAT, lng2 FLOAT) RETURNS int(11) BEGIN DECLARE latD FLOAT; DECLARE lngD FLOAT; DECLARE latS FLOAT; DECLARE lngS FLOAT; DECLARE a FLOAT; DECLARE c FLOAT; SET lat1 = RADIANS(lat1); SET lng1 = RADIANS(lng1); SET lat2 = RADIANS(lat2); SET lng2 = RADIANS(lng2); SET latD = lat2 - lat1; SET lngD = lng2 - lng1; SET latS = SIN(latD / 2); SET lngS = SIN(lngD / 2); SET a = POW(latS, 2) + COS(lat1) * COS(lat2) * POW(lngS, 2); SET c = 2 * ASIN(LEAST(1, SQRT(a))); RETURN ROUND(c * 6378137); END; $$ DELIMITER ; first off, do i have to run this query every time i want to use the function? second off, when im run this query in phpmyadmin i get the error: 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 'DELIMITER' at line 1 Quote Link to comment https://forums.phpfreaks.com/topic/176400-question-about-stored-functions/ Share on other sites More sharing options...
Mchl Posted October 3, 2009 Share Posted October 3, 2009 1. No. You just need to create function once and then it is... well... stored in the database to be used at will. 2. No idea why it happens... seems fine to me... Only thing that comes to my mind is to check whether you got all necessary privileges. [edit] Which MySQL version do you use? Quote Link to comment https://forums.phpfreaks.com/topic/176400-question-about-stored-functions/#findComment-929793 Share on other sites More sharing options...
scarhand Posted October 3, 2009 Author Share Posted October 3, 2009 i use mysql 5.1 and i still get that error in phpmyadmin. Quote Link to comment https://forums.phpfreaks.com/topic/176400-question-about-stored-functions/#findComment-929891 Share on other sites More sharing options...
Mchl Posted October 4, 2009 Share Posted October 4, 2009 Might be because in phpMyAdmin you declare the delimiter in a special field below SQL entry box. Quote Link to comment https://forums.phpfreaks.com/topic/176400-question-about-stored-functions/#findComment-930038 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.