library bulkdbinserter
Create a database writer using PDO to support multiple row insertion
sdragnev/bulkdbinserter
Create a database writer using PDO to support multiple row insertion
- Saturday, July 21, 2018
- by sdragnev
- Repository
- 1 Watchers
- 0 Stars
- 4 Installations
- PHP
- 0 Dependents
- 0 Suggesters
- 0 Forks
- 0 Open issues
- 2 Versions
- 0 % Grown
BulkDBInserter
Helper class that can buffer multiple PDO writes into one query., (*1)
Example usage, inserting 1200 records in the "accounts" table given an existing PDO connection object $pdo,
500 (default) records at a time:, (*2)
// 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