Is it possible to invoke bind_param
and execute
iteratively, or must I prepare a statement at the beginning of each iteration?
$query = $db->prepare('...');
foreach ($dataItem as $item) {
$query->bind_param($v1, $v2, ..., $item);
$query->execute();
}
$query->close();
If I do have to recreate the statement each iteration, is it possible to optimize this process?
Thank you!
There is no need to prepare a statement at the beginning of each iteration.
The concept of prepared statements is to reuse the same statement multiple times in the first place, so it's good to go to prepare once and execute it multiple times.
See also this note on the manual page.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With