When I do (in laravel):
<?php
DB::select('SELECT * FROM my_table WHERE id = :id || id = :id', [
'id' => 1,
]);
It says:
SQLSTATE[HY093]: Invalid parameter number (SQL: SELECT * FROM my_table WHERE id = :id || id = :id)
But when I do (in pure php):
<?php
$dbh = new PDO('mysql:dbname=...', '...', '...');
$stmt = $dbh->prepare('SELECT * FROM my_table WHERE id = :id || id = :id');
$r = $stmt->execute([
'id' => 1,
]);
while ($row = $stmt->fetch()) {
var_dump($row['id']);
}
It succeeds. What am I doing wrong?
P.S. Apparently, the query I ran when I encountered the issue was more meaningful.
UPD More or less real query:
SELECT id
FROM objects
WHERE ACOS(
SIN(RADIANS(lat)) * SIN(RADIANS(:lat))
+ COS(RADIANS(lat)) * COS(RADIANS(:lat)) * COS(RADIANS(:lng - lng))
) * 6371 < 10
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…