note 126436 added to pdo.begintransaction
| From: | Sbastien at main dot php dot net | Date: | Sat, 18 Sep 2021 12:34:44 +0000 |
| Subject: | note 126436 added to pdo.begintransaction | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-216973@lists.php.net to get a copy of this message | ||
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();
}
----
Server IP: 45.112.84.4
Probable Submitter: 45.112.85.242 (proxied: 82.65.8.175)
----
Manual Page -- https://php.net/manual/en/pdo.begintransaction.php
Edit -- https://main.php.net/note/edit/126436
Del: integrated -- https://main.php.net/note/delete/126436/integrated
Del: useless -- https://main.php.net/note/delete/126436/useless
Del: bad code -- https://main.php.net/note/delete/126436/bad+code
Del: spam -- https://main.php.net/note/delete/126436/spam
Del: non-english -- https://main.php.net/note/delete/126436/non-english
Del: in docs -- https://main.php.net/note/delete/126436/in+docs
Del: other reasons-- https://main.php.net/note/delete/126436
Reject -- https://main.php.net/note/reject/126436
Search -- https://main.php.net/manage/user-notes.php