Skip to content

Instantly share code, notes, and snippets.

@nd3w
Last active October 24, 2019 06:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nd3w/237f8a0c886fa225fc058a57b161e289 to your computer and use it in GitHub Desktop.
Save nd3w/237f8a0c886fa225fc058a57b161e289 to your computer and use it in GitHub Desktop.
Dynamically binding params in prepared statment
<?php
$array = [1,2,3,4,5,6,7];
$count_array = count($array);
$placeholders = implode(',', array_fill(0, $count_array, '?'));
$query = $DB->Prepare('
SELECT id, name
FROM table_name
WHERE id IN (' . $placeholders . ')
');
$list = $DB->GetAll($query, $array );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment