gpt4 book ai didi

mysql - Laravel-SQLSTATE[HY000] : General error: 2031

转载 作者:行者123 更新时间:2023-11-29 17:16:58 25 4
gpt4 key购买 nike

$pois = Home::select(\DB::raw('*, st_distance_sphere(homes.geopoint, point(?, ?)) as dist'))
->whereRaw('st_within(homes.geopoint, ST_Buffer(point(?, ?), 1))')
->orderBy('dist')
->get();

返回 Laravel - SQLSTATE[HY000]: General error: 2031 但是下面的查询有效

$pois = Home::selectRaw('*, st_distance_sphere(homes.geopoint, point('.$data["lng"].', '.$data["lat"].')) as dist')
->whereRaw('st_within(homes.geopoint, ST_Buffer(point('.$data['lng'].', '.$data['lat'].'), 1))')
->orderBy('dist')
->get();

但它很容易受到 SQLInjection 的攻击。我已经完成了 stackoverflow 中提到的建议。 PDO error: General error: 2031 [duplicate]

最佳答案

selectRaw 和 whereRaw 允许您使用占位符并将值数组作为第二个参数传递:

selectRaw('*, st_distance_sphere(homes.geopoint, point(?, ?)) as dist', [$data['lng'], $data['lat']])

关于mysql - Laravel-SQLSTATE[HY000] : General error: 2031,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51518299/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com