I am trying to resolve an issue where using Laravel's query builder I am getting no results, but when I run the same query, taken from getQueryLog using PHPMyAdmin I get expected results.
My Query builder:
DB::table('likes')
->join('geoip_blocks', function($join)
{
$join->where("ip", ">=", "block_start")
->where("ip", "<=", "block_end");
})
->join('geoip_locations', "geoip_locations.id", "=", "location_id")
->select(array("country", DB::raw("count(*) as {$this->aggregate}")))
->groupBy('country')->get();
Output from querylog:
array (size=3)
'query' => string 'select `country`, count(*) as count from `likes` inner join `geoip_blocks` on `ip` >= ? and `ip` <= ? inner join `geoip_locations` on `geoip_locations`.`id` = `location_id` group by `country`' (length=196)
'bindings' =>
array (size=2)
0 => string 'block_start' (length=11)
1 => string 'block_end' (length=9)
'time' => float 2.69
and the query I enter into phpmyadmin:
select `country`, count(*) as count from `likes` inner join `geoip_blocks` on `ip` >= block_start and `ip` <= block_end inner join `geoip_locations` on `geoip_locations`.`id` = `location_id` group by `country`
I know the above query is extremely inefficient. This was just for a proof of concept and it isn't even working so why bother go further. I've tried varying degrees of ambiguity and explicitness to no avail. Also tried removing the second join and just getting the location_id - once again without success.
Any help is greatly appreciated!