doudiyu1639 2018-09-05 18:41
浏览 114

Laravel MySql语法错误或访问冲突

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`))))';
}

Output:

"message": "SQLSTATE[42000]: Syntax error or access violation: 1064 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 '*, (6371 * acos(cos(radians(28.392200)) * cos(radians(lat)) * cos(ra' at line 1 (SQL: select * from users where exists (select *, *, (6371 * acos(cos(radians(28.392200)) * cos(radians(lat)) * cos(radians(lng) - radians(77.320801)) + sin(radians(28.392200)) * sin(radians(lat)))) AS distance from locations where users.location_id = locations.id and (6371 * acos(cos(radians(28.392200)) * cos(radians(lat)) * cos(radians(lng) - radians(77.320801)) + sin(radians(28.392200)) * sin(radians(lat)))) < 8.04672 order by distance asc) and users.deleted_at is null)",

  • 写回答

2条回答 默认 最新

  • douwen9343 2018-09-05 19:03
    关注

    First of all, next time try to formulate more like a question if you ask help on this platform.

    Secondly it never a good idea to integrate variables directly in you query. This will make your queries vulnarable for sql injections. Basics can be found here.

    By looking at your query (in the error) we can see you are to get all columns twice by using the * wildcard.

    select
        *
    from
        users
    where
        exists (
            select
                *,
                *, <-- This will throw a syntax error.
                (6371 * acos(co ... the rest of the distance calculation
    
    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?