When you have alot of transactions to make, say you are applying inserting items to the database from a loop, it will be better to use the mysqli_commit for this kind of process as it will only hit the database once.
//Wrong way
Example 1:
$con = mysqli_connect("host", "username", "password", "database") or die("Could not establish connection to database");
$users = ["chris", "james", "peter", "mark", "joe", "alice", "bob"]
for($i=0; $i<count($users); $i++){
$user= $users[$i];
$query = mysqli_query($con, "INSERT INTO users (username) VALUES ('$user') ");
}
//Correct Way
Example 2
$con = mysqli_connect("host", "username", "password", "database") or die("Could not establish connection to database");
$users = ["chris", "james", "peter", "mark", "joe", "alice", "bob"]
//Turn off autocommit
mysqli_autocommit($con, FALSE)
//Make some transactions
for($i=0; $i<count($users); $i++){
$user= $users[$i];
$query = mysqli_query($con, "INSERT INTO users (username) VALUES ('$user') ");
}
//Make a one-time hit to the database
mysqli_commit($con)
As with the Example 1, since we had 7 items in the list, this means that their will be a 7 times hit to our database which can really affect performance. But with the Example 2, since we already turned off autocommit this means that the transactions will be queued ontill will explicitly call mysqli_commit($con)