I have an array:
$bindParamsArray = Array
(
[0] => Array
(
[name] => Alex1
[email] => [email protected]
[city] => Moscow
)
[1] => Array
(
[name] => Marie
[email] => [email protected]
[city] => London
)
[2] => Array
(
[name] => Bob
[email] => [email protected]
[city] => Berlin
)
)
$chunked_array = array_chunk($data, 100);
$query = "INSERT INTO posts (`name`,`email`,`city`) VALUES(?,?,?) ";
$query .= " ON DUPLICATE KEY UPDATE email = VALUES(email), city= VALUES(city)";
foreach($chunked_array as $array)
{
$stmt = $mysqli->prepare($query);
foreach($array as $row)
{
$stmt->bind_param("sss", $row['name'], $row['email'], $row['city']);
$stmt->execute();
}
Here I bind inside the foreach loop, it is bad.
How can I do smth like this: $stmt->bind_param("sss", ...$bindParamsArray); and rewrite
foreach($array as $row)
{
$stmt->bind_param("sss", ...$bindParamsArray);
}
$stmt->execute();
Query like this must be executed:
$query = "INSERT INTO posts (`name`,`email`,`city`) VALUES(?,?,?) ON DUPLICATE KEY UPDATE email = VALUES(email), city= VALUES(city) VALUES(name1, email1, city1),VALUES(name2, email2, city2),VALUES(name1, email3, city3);
Thank You!