[英]Laravel MySql Syntax error or access violation
public static function rsine($coordinates)
{
return '(6371 * acos(cos(radians(' . $coordinates['latitude'] . '))
* cos(radians(`lat`))
* cos(radians(`lng`)
- radians(' . $coordinates['longitude'] . '))
+ sin(radians(' . $coordinates['latitude'] . '))
* sin(radians(`lat`))))';
}
输出:
"message": "SQLSTATE[42000]: 语法错误或访问冲突:1064 您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以获取在 '*, (6371 * acos) 附近使用的正确语法(cos(radians(28.392200)) \\n * cos(radians(
lat
)) \\n * cos(ra' at line 1 (SQL: select * fromusers
where exists (select *, *, (6371 * acos(cos(弧度(28.392200)) \\n * cos(radians(lat
)) \\n * cos(radians(lng
) \\n - radians(77.320801)) \\n + sin(radians(28.392200)) \\n * sin(radians(lat
))))AS从远处locations
,其中users
。location_id
=locations
。id
和(6371个* ACOS(COS(弧度(28.392200))\\ N * COS(弧度(lat
))\\ N * COS(弧度(lng
)\\ n - 弧度(77.320801)) \\n + sin(radians(28.392200)) \\n * sin(radians(lat
)))) < 8.04672 按distance
asc) 和users
deleted_at
为空)",
首先,下次如果您在此平台上寻求帮助,请尝试更像一个问题。
其次,直接在查询中集成变量绝不是一个好主意。 这将使您的查询容易受到 sql 注入的影响。 可以在这里找到基础知识。
通过查看您的查询(在错误中),我们可以看到您将使用*
通配符两次获取所有列。
select
*
from
users
where
exists (
select
*,
*, <-- This will throw a syntax error.
(6371 * acos(co ... the rest of the distance calculation
将您的方法命名为 scopeRsine() 会很好。 但是不要为此使用mysql。 改用php。 在此处查看我的回复: https : //stackoverflow.com/a/50040011/1262144
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.