Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/57.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在安装组件时创建mysql函数_Mysql_Sql_Joomla_Joomla2.5 - Fatal编程技术网

在安装组件时创建mysql函数

在安装组件时创建mysql函数,mysql,sql,joomla,joomla2.5,Mysql,Sql,Joomla,Joomla2.5,我想在Joomla 2.5组件的安装程序中包含mysql函数的创建。这就是功能: DELIMITER $$ DROP FUNCTION IF EXISTS getDistance $$ CREATE FUNCTION `getDistance` ( lat1 DECIMAL( 18, 12 ) , lng1 DECIMAL( 18, 12 ) , lat2 DECIMAL( 18, 12 ) , lng2 DECIMAL( 18, 12 ) )

我想在Joomla 2.5组件的安装程序中包含mysql函数的创建。这就是功能:

DELIMITER $$

DROP FUNCTION IF EXISTS getDistance $$


CREATE FUNCTION `getDistance` (
    lat1 DECIMAL( 18, 12 ) ,
    lng1 DECIMAL( 18, 12 ) ,
    lat2 DECIMAL( 18, 12 ) ,
    lng2 DECIMAL( 18, 12 )
    ) 
    RETURNS DECIMAL( 18, 12 ) DETERMINISTIC 

BEGIN 
DECLARE `distance` DECIMAL( 18, 12 ) ;

SELECT ( 
    6371 * 
    acos( cos( radians( lat1 ) ) * 
    cos( radians( lat2 ) ) * 
    cos( 
        radians( lng2 ) - radians( lng1 ) ) + 
    sin( radians( lat1 ) ) * 
    sin( radians( lat2 ) ) ) )
INTO `distance`;

RETURN `distance`;

END $$

DELIMITER ;
如果我使用站点用户和密码登录到phpmyadmin,那么函数就可以正常创建

我试过:

  • 将其插入到创建表的.sql文件中
  • 从安装后脚本运行它(我的首选方法,因为我可以处理错误)
  • 从管理工具栏中的按钮运行
  • 使用不同的分隔符:£
  • 将距离标识符替换为#u距离
没用

sql文件是utf8,没有bom表

如果使用sql安装程序,则会出现两次错误:

JInstaller: :Install: Error SQL DB function failed with error number 1327
Undeclared variable: distance SQL=SELECT ( 6371 * acos( cos( radians( lat1 ) ) * cos( radians( lat2 ) ) * cos( radians( lng2 ) - radians( lng1 ) ) + sin( radians( lat1 ) ) * sin( radians( lat2 ) ) ) ) INTO `distance`;
SQL =

SELECT ( 
    6371 * 
    acos( cos( radians( lat1 ) ) * 
    cos( radians( lat2 ) ) * 
    cos( 
        radians( lng2 ) - radians( lng1 ) ) + 
    sin( radians( lat1 ) ) * 
    sin( radians( lat2 ) ) ) )
INTO `distance`;
如果我从组件的控制器中运行$db->getErrorMsg(),则查询$db->getErrorMsg()时会出现此错误

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 'DELIMITER ££' at line 1 SQL=DELIMITER ££ DROP FUNCTION IF EXISTS getDistance ££ CREATE FUNCTION `xxyx_getDistance` ( lat1 DECIMAL( 18, 12 ) , lng1 DECIMAL( 18, 12 ) , lat2 DECIMAL( 18, 12 ) , lng2 DECIMAL( 18, 12 ) ) RETURNS DECIMAL( 18, 12 ) DETERMINISTIC BEGIN DECLARE `xxyx_distance` DECIMAL( 18, 12 ) ; SELECT ( 6371 * acos( cos( radians( lat1 ) ) * cos( radians( lat2 ) ) * cos( radians( lng2 ) - radians( lng1 ) ) + sin( radians( lat1 ) ) * sin( radians( lat2 ) ) ) ) INTO `xxyx_distance`; RETURN `xxyx_distance`; END ££ DELIMITER ;

DELIMITER
是一个客户端构造,告诉客户端语句的结尾在哪里,而不是服务器


如果您用从“CREATE FUNCTION”到函数定义的最后一个“END”的所有内容制作一个字符串。。。“结束”后不需要“分隔符”语句和“$$”或其他符号。。。并将该字符串作为对连接对象的查询执行,服务器应该理解它。“如果存在函数名,则删除函数”也是一样的,首先执行。

谢谢你,Michael,你救了我一周:-)