I have a cache table which is rebuilt occasionally:
$Sql = 'INSERT INTO someTable (...fields...) VALUES (...values...)';
$stmt = $pdo->prepare($sql, array(PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY));
$items_to_insert[] = array();
foreach ($item as $i) {
$details = array();
// Lots of things here, such as:
$details[':username'] = $['username'];
$items_to_insert[] = $details
}
foreach ($items_to_insert as $i) {
$stmt->execute($i);
}
What should I take into consideration to decide if it would be better off to run $stmt->execute()
in the first foreach
and to eliminate the second foreach
and the $items_to_insert
array? Is there any way to have the execute()
run concurrently with the next foreach
loop? This is for an application that will likely run on a variety of hardware so I am not interested in the specific case of benchmarking on my workstation, but rather I am interested in learning the intricacies of situation to make better use of PDO best practices.