Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6648673
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:40:59+00:00 2026-05-26T00:40:59+00:00

I have function to cal miles distance: DELIMITER // DROP FUNCTION IF EXISTS distance_miles//

  • 0

I have function to cal miles distance:

DELIMITER //                                                                                      
    DROP FUNCTION IF EXISTS distance_miles//                                                      
    CREATE FUNCTION distance_miles(lat1 FLOAT, lon1 FLOAT, lat2 FLOAT, lon2 FLOAT)                
    RETURNS FLOAT(120)                                                                            
    BEGIN                                                                                         
        DECLARE pi, q1, q2, q3 FLOAT;                                                             
        DECLARE rads FLOAT DEFAULT 0;                                                             
        SET pi = PI();                                                                            
        SET lat1 = lat1 * pi / 180;                                                               
        SET lon1 = lon1 * pi / 180;                                                               
        SET lat2 = lat2 * pi / 180;                                                               
        SET lon2 = lon2 * pi / 180;                                                               
        SET q1 = COS(lon1-lon2);                                                                  
        SET q2 = COS(lat1-lat2);                                                                  
        SET q3 = COS(lat1+lat2);                                                                  
        SET rads = ACOS( 0.5*((1.0+q1)*q2 - (1.0-q1)*q3) );                                       
        RETURN 6378.388 * rads * 0.621371192;                                                     
    END//                                                                                         
DELIMITER ;                                                                                       

I run this as 1 query from phpmyadmin. It run’s Ok. But i dont see this in routines table in information_schema.

Also, when am trying run this from php i got an error

 $mdb->query($mdb->mes("
     DELIMITER //                                                                                      
         DROP FUNCTION IF EXISTS distance_miles//                                                      
         CREATE FUNCTION distance_miles(lat1 FLOAT, lon1 FLOAT, lat2 FLOAT, lon2 FLOAT)                
         RETURNS FLOAT(120)                                                                            
         BEGIN                                                                                         
             DECLARE pi, q1, q2, q3 FLOAT;                                                             
             DECLARE rads FLOAT DEFAULT 0;                                                             
             SET pi = PI();                                                                            
             SET lat1 = lat1 * pi / 180;                                                               
             SET lon1 = lon1 * pi / 180;                                                               
             SET lat2 = lat2 * pi / 180;                                                               
             SET lon2 = lon2 * pi / 180;                                                               
             SET q1 = COS(lon1-lon2);                                                                  
             SET q2 = COS(lat1-lat2);                                                                  
             SET q3 = COS(lat1+lat2);                                                                  
             SET rads = ACOS( 0.5*((1.0+q1)*q2 - (1.0-q1)*q3) );                                       
             RETURN 6378.388 * rads * 0.621371192;                                                     
         END//                                                                                         
     DELIMITER ;                                                                                       

 "));                                                                                      

this one:

error:1064
CALLED:[Resource id #8]***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 ‘\r\nDELIMITER ~~ ‘ at line 1
in db query: [\r\nDELIMITER ~~

Pls help me, what happens? Completely dont understood this.

  1. How to look if function exists?
  2. It will appear in information_shema table ROUTINES?
  3. why is problem with php running this query?

====

SELECT ROUTINE_TYPE, ROUTINE_NAME
FROM INFORMATION_SCHEMA.ROUTINES

Also – dont show this function … strange this all…


Also this:
SHOW CREATE FUNCTION distance_miles

Answers:
MySQL said: Documentation

1305 – FUNCTION distance_miles does not exist

…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T00:41:00+00:00Added an answer on May 26, 2026 at 12:41 am

    mysql_query doesn’t support multiqueries. See manual.

    You just need to remove the DELIMITER lines, split the queries by yourself, and the CREATE FUNCTION should work.

     $mdb->query($mdb->mes("DROP FUNCTION IF EXISTS distance_miles"));
     $mdb->query($mdb->mes("CREATE FUNCTION distance_miles(lat1 FLOAT, lon1 FLOAT, lat2 FLOAT, lon2 FLOAT)                
             RETURNS FLOAT(120)                                                                            
             BEGIN                                                                                         
                 DECLARE pi, q1, q2, q3 FLOAT;                                                             
                 DECLARE rads FLOAT DEFAULT 0;                                                             
                 SET pi = PI();                                                                            
                 SET lat1 = lat1 * pi / 180;                                                               
                 SET lon1 = lon1 * pi / 180;                                                               
                 SET lat2 = lat2 * pi / 180;                                                               
                 SET lon2 = lon2 * pi / 180;                                                               
                 SET q1 = COS(lon1-lon2);                                                                  
                 SET q2 = COS(lat1-lat2);                                                                  
                 SET q3 = COS(lat1+lat2);                                                                  
                 SET rads = ACOS( 0.5*((1.0+q1)*q2 - (1.0-q1)*q3) );                                       
                 RETURN 6378.388 * rads * 0.621371192;                                                     
             END                                                                        
     "));     
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code currently: $('#cal').datepicker({ onSelect: function(dateText, inst) { var dateAsString = dateText;
I have been able to create php function to determine a list of zip
I have a jQuery callback function. In that function I want it to change
A simple question I suspect. I have the simple function definition makePatientFixture :: [
I have my function as follows <script type=text/javascript> $(function() { $('#ctl00_ContentPlaceHolder1_TextBox2').datepick(); }); function showDate(date)
In my view I have an ajax call: $(.previous).click(function() { $.ajax({ type: POST, url:
I have a select menu that looks like this: <select id ="cal-category-select"> <option value="/event-sort/list/2009/9/sports/">Sports
I have a function as below to generate unique ID for my application public
I have this php script: function hoeveelzijner ($jaar, $id) { function hoeveelhoeveel($beginstamp, $endstamp, $id)
I have a functional datagrid that responds to itemClick events. Everything works, except that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.