How to use "WHERE IN" in MYSQLi Prepared Statements in PHP?

$ids = [1,2,3,4,5]; // any array of ids
$count = count($id);
$placeholders = implode(',', array_fill(0, $count, '?'));
$bindStr = str_repeat('i', $count);

$stmt = $mysqli -> prepare("SELECT * FROM table WHERE id IN ($placeholders)");
$stmt -> bind_param($bindStr, ...$ids);
$stmt -> execute();

Tagged: PHP MYSQLi
Written By
Supun Kavinda
Written On
Apr 17, 2019
Last Updated On
Apr 17, 2019
Latest on Hyvor Developer
Creating a Real-Time Chat App with PHP and Node.js
All About MYSQLI Prepared Statements in PHP
Image Upload with AJAX, PHP, and MYSQL - The Beginner's Guide
PHP Contact Form - The Email Method
Related Articles