Do I need to roll back if commit fails?

This seems like a pretty simple question, but I could not find the final MySQL-specific answers. Look at this:

$mysqli->autocommit(false); //Start the transaction
$success = true;    

/* do a bunch of inserts here, which will be rolled back and
   set $success to false if they fail */

if ($success) {
    if ($mysqli->commit()) {
        /* display success message, possibly redirect to another page */
    }
    else {
        /* display error message */
        $mysqli->rollback(); //<----------- Do I need this?
    }
}

$mysqli->autocommit(true); //Turns autocommit back on (will be turned off again if needed)

//Keep running regardless, possibly executing more inserts

, , , script, , , exit(), , -, (?), , , , ? , , ( PHP autocommit ) $mysqli->commit() , , , ?

, , .

: , , . , , , , , , . , : commit , ?

+4

All Articles