简体   繁体   English

我如何在mysql中使用函数

[英]How can i use a function in mysql

I have designed a function in mysql to calculate distance between two coordinates. 我已经在mysql中设计了一个函数来计算两个坐标之间的距离。

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. 现在在我的php文件中,我具有这四个参数来传递此函数。

but i dont know how can i call this function. 但我不知道如何调用此功能。 please tell me how can call this function ? 请告诉我如何调用此函数?

虽然我发现这种结构很奇怪,并且对为什么有人会在MySQL中实现这些东西感到好奇,但它的工作方式是

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

像这样select getDistance(1,2,3,4)

You can always use string concatenation: 您始终可以使用字符串连接:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM