PHP 8.5.0 Alpha 4 available for testing

Voting

: min(three, eight)?
(Example: nine)

The Note You're Voting On

Sbastien
3 years ago
A way to use transaction and prepared statement to speed-up bulk INSERTs :

<?php

// ...

$insert = $pdo->prepare('INSERT INTO table (c1, c2, c3) VALUES (?, ?, ?)');
$bulk = 3_000; // To adjust according to your data/system
$rows = 0;

$pdo->beginTransaction();
while (
$entry = fgetcsv($fp)) {
$insert->execute($entry);
if (++
$rows % $bulk === 0) {
$pdo->commit();
$pdo->beginTransaction();
}
}
if (
$pdo->inTransaction()) { // Remaining rows insertion
$pdo->commit();
}

<< Back to user notes page

To Top