php pdo bindvalue array

Solutions on MaxInterview for php pdo bindvalue array by the best coders in the world

showing results for - "php pdo bindvalue array"
Neele
16 Nov 2017
1<?php
2$ids     = array(1, 2, 3, 7, 8, 9);
3$inQuery = implode(',', array_fill(0, count($ids), '?'));
4
5$db = new PDO(...);
6$stmt = $db->prepare(
7    'SELECT *
8     FROM table
9     WHERE id IN(' . $inQuery . ')'
10);
11
12// bindvalue is 1-indexed, so $k+1
13foreach ($ids as $k => $id)
14    $stmt->bindValue(($k+1), $id);
15
16$stmt->execute();
17?>
18