laravel 查询没有返回值 - 奇怪的 pdo
laravel query not returning values - strange pdo
我遇到了一个奇怪的问题,它真的难倒了我。我正在使用 laravel 来构建我的网站,并且我刚刚编写了一个脚本来充当搜索引擎。它被构建然后运行。
我只是 运行宁 $query->get()
,$query
是 laravel 建设者 class。这是查询内容:
select * from (
select `l`.*, round(
d.distance_unit
* DEGREES(ACOS(COS(RADIANS(p.latitude))
* COS(RADIANS(z.latitude))
* COS(RADIANS(p.longitude - z.longitude))
+ SIN(RADIANS(p.latitude))
* SIN(RADIANS(z.latitude)))),
2
) AS distance, `d`.`radius` from `listings` as `l`
inner join `horses` as `x` on `x`.`id` = `l`.`listing_id`
inner join `suburbs` as `z` on `z`.`id` = `l`.`suburb_id`
inner join (select 50 as radius, 111.045 as distance_unit) as d on 1 = 1
inner join `suburbs` as `p` on `p`.`id` = 1
where (
`z`.`latitude` between
?
and
?
and `z`.`longitude` between
?
and
?
)
) as sub
where `distance` <= `radius`
order by `created_at` desc
limit 9 offset 0
查询绑定:
[bindings] => Array
(
[0] => Illuminate\Database\Query\Expression Object
(
[value:protected] => p.latitude - (d.radius / d.distance_unit)
)
[1] => Illuminate\Database\Query\Expression Object
(
[value:protected] => p.latitude + (d.radius / d.distance_unit)
)
[2] => Illuminate\Database\Query\Expression Object
(
[value:protected] => p.longitude - (d.radius / (d.distance_unit * COS(RADIANS(p.latitude))))
)
[3] => Illuminate\Database\Query\Expression Object
(
[value:protected] => p.longitude + (d.radius / (d.distance_unit * COS(RADIANS(p.latitude))))
)
)
那是laravel运行的查询。当我打印 sql 时。但是我终其一生都无法弄清楚为什么当 phpmyadmin 中的 sql i 运行 有值时它没有 return 值。 (我所做的就是将绑定添加到问号,然后在 phpmyadmin 中添加 运行)。我得出的结论是 laravels PDO 必须以不同的方式做某事或以不同的方式加入他们。我正在为每个值使用 DB::raw()
方法。
我通过为 mysql 服务器配置 my.ini
设法找到了我的问题。我在 [mysqld]
下打开了 general_log_file = "queries.log"
。然后运行SET global general_log = 1;
在mysql.
这向我展示了查询的问题。绑定被插入引号中,即使我使用的是 DB::raw()
。所以我只需要想办法删除它们。
我遇到了一个奇怪的问题,它真的难倒了我。我正在使用 laravel 来构建我的网站,并且我刚刚编写了一个脚本来充当搜索引擎。它被构建然后运行。
我只是 运行宁 $query->get()
,$query
是 laravel 建设者 class。这是查询内容:
select * from (
select `l`.*, round(
d.distance_unit
* DEGREES(ACOS(COS(RADIANS(p.latitude))
* COS(RADIANS(z.latitude))
* COS(RADIANS(p.longitude - z.longitude))
+ SIN(RADIANS(p.latitude))
* SIN(RADIANS(z.latitude)))),
2
) AS distance, `d`.`radius` from `listings` as `l`
inner join `horses` as `x` on `x`.`id` = `l`.`listing_id`
inner join `suburbs` as `z` on `z`.`id` = `l`.`suburb_id`
inner join (select 50 as radius, 111.045 as distance_unit) as d on 1 = 1
inner join `suburbs` as `p` on `p`.`id` = 1
where (
`z`.`latitude` between
?
and
?
and `z`.`longitude` between
?
and
?
)
) as sub
where `distance` <= `radius`
order by `created_at` desc
limit 9 offset 0
查询绑定:
[bindings] => Array
(
[0] => Illuminate\Database\Query\Expression Object
(
[value:protected] => p.latitude - (d.radius / d.distance_unit)
)
[1] => Illuminate\Database\Query\Expression Object
(
[value:protected] => p.latitude + (d.radius / d.distance_unit)
)
[2] => Illuminate\Database\Query\Expression Object
(
[value:protected] => p.longitude - (d.radius / (d.distance_unit * COS(RADIANS(p.latitude))))
)
[3] => Illuminate\Database\Query\Expression Object
(
[value:protected] => p.longitude + (d.radius / (d.distance_unit * COS(RADIANS(p.latitude))))
)
)
那是laravel运行的查询。当我打印 sql 时。但是我终其一生都无法弄清楚为什么当 phpmyadmin 中的 sql i 运行 有值时它没有 return 值。 (我所做的就是将绑定添加到问号,然后在 phpmyadmin 中添加 运行)。我得出的结论是 laravels PDO 必须以不同的方式做某事或以不同的方式加入他们。我正在为每个值使用 DB::raw()
方法。
我通过为 mysql 服务器配置 my.ini
设法找到了我的问题。我在 [mysqld]
下打开了 general_log_file = "queries.log"
。然后运行SET global general_log = 1;
在mysql.
这向我展示了查询的问题。绑定被插入引号中,即使我使用的是 DB::raw()
。所以我只需要想办法删除它们。