Mysql
 SQL >> Datenbank >  >> RDS >> Mysql

Prepared Statement mit MySQL IN-Klausel und Sortierung

Dynamische Platzhalter lassen sich sicher erzeugen:

$ids = array(1, 5, 18, 25);
$clause = implode(',', array_fill(0, count($ids), '?'));
$stmt = $mysqli->prepare(
  'SELECT * FROM somewhere WHERE `id` IN (' . $clause . ') ORDER BY `name`;'
);
call_user_func_array(array($stmt, 'bind_param'), $ids);
$stmt->execute();