I am trying to execute a query that shows only articles inside this array $res
. It contains article IDs
$res = Array ( [0] => 42 [1] => 41 );
$res1 = $res;
$res2 = $res;
$Search = $db->prepare("
SELECT * FROM articles
WHERE id IN :res1
ORDER BY FIELD(id, :res2);
");
$Search->execute([
':res1' => $res1,
':res2' => $res2
]);
but it is returnig this error
Fatal error: Uncaught PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '? ORDER BY FIELD(id, ?)' at line 2 in C:\xampp\htdocs\index.php:16 Stack trace: #0 C:\xampp\htdocs\index.php(16): PDO->prepare('\r\n\t\t\tSELECT * F...')