Is there a way to do transactions with prepared statements?
I mean can I use the following example with $mysqli->autocommit(FALSE);
and $mysqli->
Prepared statements and transactions are unrelated techniques and technologies.
You may wish to issue the START TRANSACTION
and COMMIT
/ROLLBACK
commands directly instead of using the dedicated methods. They are functionally equivalent.
For your loop, you'd issue the START TRANSACTION
before your prepare
, then your COMMIT
after the loop exits. You probably should not try to open a transaction after a prepared statement has been started but before it's been executed.
For some reason, they didn't add a "start transaction" command in favor of turning off autocommit. It's one of those weird things about mysqli that makes me always recommend PDO instead. :) Opening a transaction implicitly turns off autocommit for the duration of the transaction.