Today it was with PDO and memory usage.
When doing large data inserts with transactions, you should
always do your query preparation outside of your loop.
always do your query preparation outside of your loop.
For example:
$datasource->open();
$datasource->beginTransaction();
$p = $datasource->prepare(‘INSERT a SET b = :c’);
while(!feof($line)) {
$p->bindValue(‘:c’, $line);
$p->execute();
}
$datasource->commit();
If the query prepare is moved into the loop, an exorbitant
amount of memory and time is consumed parsing the query every
iteration. For a million inserts, this can result in
exceeding allowed memory usage.
amount of memory and time is consumed parsing the query every
iteration. For a million inserts, this can result in
exceeding allowed memory usage.