I have an array that I am preparing for a SQL query, so following the steps to make it secure as possible. Attempting the following:
First I implode the array - I want the string result to come out as 'string1','string2','string3' and so on:
$in = "'" . implode("','", array_fill(0, count($finalArray), '?')) . "'";
I make my query:
$query = <<<SQL
UPDATE products SET `Status` = 'Reserved' WHERE `SerialNumber` in ($in);
SQL;
$query = <<<SQL
And prepare the statement variable:
$statement = $mysqli->prepare($query);
Then I attempt a bind_param with str_repeat, and this is where things go wrong:
$statement->bind_param(str_repeat('\'s\',', count($finalArray)), ...$finalArray);
I get:
mysqli_stmt::bind_param(): Number of elements in type definition string doesn't match number of bind variables
Does anyone know why I am getting this and how I can resolve it?