Veo que miarroba no soporta Procedimientos Almacenados (Store Procedure Language). Podeis Confirmar ?
Intentado el siguiente, pero no veo que no se almacen, luego no es ejecutable desde PHP::
// MyDistance-----------------------------------------------------------------MyDistance
$spl0 = "DROP FUNCTION IF EXISTS MyDistance ";
$spl1 = "CREATE FUNCTION MyDistance(lat1 DOUBLE, lng1 DOUBLE, lat2 DOUBLE, lng2 DOUBLE) ";
$spl1 = $spl1."RETURNS VARCHAR(12) ";
$spl1 = $spl1."BEGIN ";
//$km = 111.302; $degtorad = 0.01745329; $radtodeg = 57.29577951;
$spl1 = $spl1."DECLARE KM DOUBLE; ";
$spl1 = $spl1."DECLARE DEGTORAD DOUBLE; ";
$spl1 = $spl1."DECLARE RADTODEG DOUBLE; ";
$spl1 = $spl1."DECLARE DLONG DOUBLE; ";
$spl1 = $spl1."DECLARE DVALUE DOUBLE; ";
$spl1 = $spl1."DECLARE DD DOUBLE; ";
$spl1 = $spl1."DECLARE RESULT VARCHAR(12); ";
$spl1 = $spl1."SET KM = 111.302; "; // EL ORDEN ES IMPRTANTE
$spl1 = $spl1."SET DEGTORAD = 0.01745329; ";
$spl1 = $spl1."SET RADTODEG = 57.29577951; ";
//$dlong = ($long1 - $long2);
$spl1 = $spl1."SET DLONG = lng1 - lng2; ";
//$dvalue = (sin($lat1 * $degtorad) * sin($lat2 * $degtorad)) + (cos($lat1 * $degtorad) * cos($lat2 * $degtorad) * cos($dlong * $degtorad));
$spl1 = $spl1."SET DVALUE = (SIN(lat1 * DEGTORAD) * SIN(lat2 * DEGTORAD)); ";
$spl1 = $spl1."SET DVALUE = DVALUE + (COS(lat1 * DEGTORAD) * COS(lat2 * DEGTORAD) * COS(DLONG * DEGTORAD)); ";
//$dd = acos($dvalue) * $radtodeg;
$spl1 = $spl1."SET DD = ACOS(DVALUE) * RADTODEG; ";
//return round(($dd * $km), 2);
$spl1 = $spl1."SET RESULT = CONCAT(ROUND((DD * KM), 3) , ' Km'); "; // number_format($row['MiAvg'], 3, '.', '');
$spl1 = $spl1."RETURN RESULT; ";
$spl1 = $spl1."END; ";
if ( !mysqli_query($link, $spl0) ) {
echo "User Defined Function failed: <br>(" . mysqli_errno($link) . ") " . mysqli_error($link) ."<br>"; }
if ( !mysqli_query($link, $spl1) ) {
echo "User Defined Function failed: <br>(" . mysqli_errno($link) . ") " . mysqli_error($link) ."<br>"; }