Php 自定义函数在mysql查询中不起作用如何使其起作用?

Php 自定义函数在mysql查询中不起作用如何使其起作用?,php,sql,Php,Sql,我在处理一个项目时遇到了一个sql查询,该项目以前在php 5上运行良好。现在将其迁移到php 7,查询中有一种自定义函数,它使用4个参数,其中两个参数是通过php变量在本地传递的,但其他参数是通过引用表列名传递的。就我所知,我猜不出它在PHP5Live网站上是如何工作的。您可以看到sql查询中使用了CalculateInstance函数 <b>Fatal error</b>: Uncaught PDOException: SQLSTATE[42000]: Syntax

我在处理一个项目时遇到了一个sql查询,该项目以前在php 5上运行良好。现在将其迁移到php 7,查询中有一种自定义函数,它使用4个参数,其中两个参数是通过php变量在本地传递的,但其他参数是通过引用表列名传递的。就我所知,我猜不出它在PHP5Live网站上是如何工作的。您可以看到sql查询中使用了CalculateInstance函数

<b>Fatal error</b>:  Uncaught PDOException: SQLSTATE[42000]: Syntax error or access violation: 1305 FUNCTION mydb_db.calculateDistance does not exist in ....


$String_SQL = "Insert into pogopro_search_engine_result_cache(user_id,project_id,merchant_id,match_items,business_name,certifications,has_work_permit,has_promotion,service_rating_count,gps_lat,gps_long,service_rating_amount,distance,logo_url) "
          ."Select ".$user_id." as user_id,".$project_id." as project_id,a.merchant_id,count(a.pro_service_category_id) as match_items,b.business_name,b.certifications,b.has_work_permit,b.has_promotion,b.service_rating_count,b.business_gps_lat as gps_lat,b.business_gps_long as gps_long,b.service_rating_amount,calculateDistance(".$gps_lat.",".$gps_long.",b.business_gps_lat,b.business_gps_long) as distance,b.logo_url "
          ."From pogopro_pro_offer_services a,rv_merchants b ";
    if ($service_language>0)
        $String_SQL .=",pogopro_speak_languages c ";
        $String_SQL .="Where a.merchant_id = b.id and a.merchant_id <> ".$merchant_id_of_user." " 
          //."AND pro_service_category_id in (".$service_category_code.") "
          ."AND id_service_category in (".$service_category_code.") "      
          ."AND (b.service_rating_amount/b.service_rating_count>=".$service_rating_start.") ";
   if ($service_language>0)
        $String_SQL .="AND c.merchant_id = a.merchant_id AND c.language_id = ".$service_language." "; 
    #$String_SQL .= "AND b.business_city = '".$target_city."' " 
    $String_SQL .="AND calculateDistance(".$gps_lat.",".$gps_long.",b.business_gps_lat,b.business_gps_long) <=".$distance_from_range." "
                ."AND calculateDistance(".$gps_lat.",".$gps_long.",b.business_gps_lat,b.business_gps_long) <= b.service_distance_range "
                ."Group by a.merchant_id Order By count(a.pro_service_category_id) DESC, a.merchant_id"; 
    //echo $String_SQL;
    $status = $this->db_conn->query($String_SQL);

它就在错误消息中,函数mydb_db.calculateInstance在…中不存在。您能告诉我,是否可以按照查询中提到的方式在查询中调用自定义函数,例如php函数?将两个cdb表列值作为参数引用?CalculateInstance是PHP函数吗?从理论上讲,您可以从查询中调用它,但这会很混乱,并且容易出现问题。