5

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!

1 Answer 1

7

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.