laravel查询不返回值-奇怪的pdo


laravel query not returning values - strange pdo

我遇到了一个奇怪的问题,它真的让我很困惑。我正在使用laravel来构建我的网站,我刚刚写了一个脚本来充当搜索引擎。它先构建,然后运行。


我只是在运行$query->get(),而$query是一个laravel构建器类。这是查询内容:


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返回值时,它不返回值。(我所做的就是将绑定添加到问号中,然后在phpmyadmin中运行)。我得出的结论是,laravels PDO一定在做一些不同的事情,或者以不同的方式加入他们。对于这些值中的每一个,我都使用DB::raw()方法。

我通过为mysql服务器配置my.ini找到了问题。我打开[mysqld]下的general_log_file = "queries.log"。然后在mysql中运行SET global general_log = 1;


这向我展示了我的查询问题。绑定是用引号插入的,尽管我使用的是DB::raw()。所以我只需要想办法把它们去掉。