I have a script which inserts lot's of data. This data is mostly a replication of the previous insert, however at least one value is different. Therefore, I prepare the statement and bind the params to execute and repeat.
However, I tried to write this to a prepared batch insert inserting 1000 rows tops at a time. Unfortunately, I can't get it to work. The code I'm using right now is just inserting the entire data at once. However, this is not wanted, since the amount of data may be a lot bigger than tested with.
The code I use now (Bulk insert all at once):
$Data = array(
array("1", "2", "3", "4"),
array("1", "2", "3", "5"),
array("1", "2", "3", "6"),
array("1", "2", "3", "7"),
array("1", "2", "3", "8"),
//ETC
);
//AS YOU CAN SEE, ONLY COL4 CHANGES
$sql = $mysqli->prepare("INSERT INTO `Table` (Col1, Col2, Col3, Col4) VALUES ".implode(', ', array_fill(0, count($Data), "(?, ?, ?, ?)")));
foreach ($Data as $InsertData) {
$sql->bind_param('iiii', $InsertData[0], $InsertData[1], $InsertData[2], $InsertData[3]);
}
$sql->execute();
What I want to achieve is that the data will be inserted with a prepared statement like above, but with a limit of 1000 (or any other number) per batch. I can't get this to work. I tried to use array_splice
and other methods, but I couldn't get it to work.