When I do (in laravel):
1,
]);
It says:
From what I can see it all comes down to mysql
being unable to deal with named parameters.
mysqli::prepare:
This parameter can include one or more parameter markers in the SQL statement by embedding question mark (?) characters at the appropriate positions.
pdo::prepare:
You must include a unique parameter marker for each value you wish to pass in to the statement when you call PDOStatement::execute(). You cannot use a named parameter marker of the same name more than once in a prepared statement, unless emulation mode is on.
Laravel has emulation mode disabled by default. One can enable it in config/database.php
by adding 'options' => [PDO::ATTR_EMULATE_PREPARES => TRUE]
to connection settings. That way you will get the same result as in pure php. Not sure that's a good idea, though.
I usually solve that using a CROSS JOIN with a "constant" derived table (subquery in FROM clause). Then I can reuse the parameters as many times as I want.
SELECT id
FROM objects o
CROSS JOIN (SELECT :lat as lat, :lng as lng) params
WHERE ACOS(
SIN(RADIANS(o.lat)) * SIN(RADIANS(params.lat))
+ COS(RADIANS(o.lat)) * COS(RADIANS(params.lat)) * COS(RADIANS(params.lng - o.lng))
) * 6371 < 10