MySQL 1064 错误,适用于命令行和 phpMyAdmin;不在应用程序中

发布于 2024-08-20 04:01:23 字数 1451 浏览 15 评论 0原文

这是我的查询:

select * 
  from (select *, 3956 * 2 * ASIN(SQRT(POWER(SIN(RADIANS(45.5200077 - lat)/ 2), 2) + COS(RADIANS(45.5200077)) * COS(RADIANS(lat)) * POWER(SIN(RADIANS(-122.6942014 - lng)/2),2))) AS distance 
          from stops 
      order by distance, route asc) as p 
group by route, dir 
order by distance asc 
   limit 10

这在命令行和 PHPMyAdmin 中运行良好。我正在使用 Dbslayer 通过 JavaScript 后端连接到 MySQL,请求是返回 1064 错误。

以下是编码后的 DBSlayer 请求字符串:

http://localhost:9090/db?{%22SQL%22:%22select%20* %20来自%20%28选择%20*,%203956%20*%202%20*%20ASIN%28SQRT%28POWER%28SIN%28RADIANS%2845.5200077%20-%20lat%29/%202%29,%202%29% 20+%20COS%28RADIANS%2845.5200077%29%29%20*%20COS%28RADIANS%28lat%29%29%20*%20POWER%28SIN%28RADIANS%28-122.6942014%20-%20lng%29/2%29, 2%29%29%29%20AS%20distance%20from%20%60stops%60%20order%20by%20%60distance%60、%20%60route%60%20asc%29%20as%20p%20group%20by%20 %60route%60,%20%60dir%60%20order%20by%20%60distance%60%20asc%20limit%2010%22}

响应:

{"MYSQL_ERRNO" : 1064 , "MYSQL_ERROR" : "您的 SQL 语法有错误;请检查与您的 MySQL 服务器版本相对应的手册,以了解在 '(RADIANS(45.5200077)) 附近使用的正确语法 * COS (RADIANS(lat)) * POWER(SIN(RADIANS(-122.6942014 - lng' at line 1" , "SERVER" : "trimet"}

)

谢谢!

Here is my query:

select * 
  from (select *, 3956 * 2 * ASIN(SQRT(POWER(SIN(RADIANS(45.5200077 - lat)/ 2), 2) + COS(RADIANS(45.5200077)) * COS(RADIANS(lat)) * POWER(SIN(RADIANS(-122.6942014 - lng)/2),2))) AS distance 
          from stops 
      order by distance, route asc) as p 
group by route, dir 
order by distance asc 
   limit 10

This works fine at the command line and in PHPMyAdmin. I'm using Dbslayer to connect to MySQL via my JavaScript backend, and the request is returning a 1064 error.

Here is the encoded DBSlayer request string:

http://localhost:9090/db?{%22SQL%22:%22select%20*%20from%20%28select%20*,%203956%20*%202%20*%20ASIN%28SQRT%28POWER%28SIN%28RADIANS%2845.5200077%20-%20lat%29/%202%29,%202%29%20+%20COS%28RADIANS%2845.5200077%29%29%20*%20COS%28RADIANS%28lat%29%29%20*%20POWER%28SIN%28RADIANS%28-122.6942014%20-%20lng%29/2%29,2%29%29%29%20AS%20distance%20from%20%60stops%60%20order%20by%20%60distance%60,%20%60route%60%20asc%29%20as%20p%20group%20by%20%60route%60,%20%60dir%60%20order%20by%20%60distance%60%20asc%20limit%2010%22}

And the response:

{"MYSQL_ERRNO" : 1064 , "MYSQL_ERROR" : "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 '(RADIANS(45.5200077)) * COS(RADIANS(lat)) * POWER(SIN(RADIANS(-122.6942014 - lng' at line 1" , "SERVER" : "trimet"}

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦纸 2024-08-27 04:01:23

问题的一个可能的直接根源是 URL 编码。我看到加号运算符按原样传输。这很危险,因为在传统编码中,+ 过去表示空格http://www.faqs.org/rfcs/rfc1738

A possible immediate source of your problem is the URL encoding. I see the plus operator is transmitted as-is. That's dangerous, because + used to mean space in the traditional encoding. http://www.faqs.org/rfcs/rfc1738

眼波传意 2024-08-27 04:01:23
...distance%60%20asc%20...

你是如何转义sql的?看起来您缺少“路线”,因此上面显示“距离,asc”。看起来从那里开始走下坡路。

...distance%60%20asc%20...

How are you escaping the sql? Looks like you're missing the "route", so the above reads "distance, asc". Looks like it goes downhill from there.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文