sdragnev/bulkdbinserter

Create a database writer using PDO to support multiple row insertion

v1.2 2021-12-27 15:42 UTC

This package is auto-updated.

Last update: 2024-09-27 21:42:55 UTC


README

Helper class that can buffer multiple PDO writes into one query.

Example usage, inserting 1200 records in the "accounts" table given an existing PDO connection object $pdo, 500 (default) records at a time:

// Inserts 1200 records in 3 queries (500 + 500 + 200)
$writer = new BulkInserter($pdo, "accounts", ["id", "name"]);
// $writer->setBatch(600); // optionally set the buffer size to a different number

for ($i = 0; $i < 1200; $i++) {
    $writer->write([$i, "John $i"]);
}

$writer->flush(true);   // flushes the remaining buffer