Pushpendra Kuntal
Pushpendra Kuntal

Reputation: 6186

How can i use a function in mysql

I have designed a function in mysql to calculate distance between two coordinates.

function is like this:-

getDistance(arg1,arg2,arg3,arg4)

   {

       //calculate distance

         return distance;

}

now in my php file, i have these four argument to pass in this function.

but i dont know how can i call this function. please tell me how can call this function ?

Upvotes: 0

Views: 74

Answers (3)

GManz
GManz

Reputation: 1659

You can always use string concatenation:

<?php
mysql_query('SELECT getDistance('.$a.', '.$b.', '.$b.', '.$b.')');
?>

Upvotes: 0

glglgl
glglgl

Reputation: 91017

While I find this structure quite strange, and feel curious about why someone would implement such things in MySQL, the way it should work is with

mysql_query(sprintf("select getDistance(%d,%d,%d,%d)", $a, $b, $c, $d);

Upvotes: 4

triclosan
triclosan

Reputation: 5714

like this select getDistance(1,2,3,4)

Upvotes: 2

Related Questions