PHP mysqli_autocommit() Function
Definition
The mysqli_autocommit() function turns on or off auto-committing database modifications.
Syntax
PHP mysqli_autocommit() Function has the following syntax.
mysqli_autocommit(connection,mode);
Parameter
Parameter | Is Required | Description |
---|---|---|
connection | Required. | MySQL connection |
mode | Required. | FALSE turns auto-commit off. TRUE turns auto-commit on |
Return
It returns TRUE on success or FALSE on failure.
Related functions
The mysqli_commit() function commits the current transaction. The mysqli_rollback() function rolls back the current transaction.
Example
The following code turns off auto-committing, make some queries, then commit the queries.
<?php/* w ww . jav a 2s.c o m*/
$con=mysqli_connect("localhost","my_user","my_password","my_db");
if (mysqli_connect_errno($con)){
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
// Set autocommit to off
mysqli_autocommit($con,FALSE);
// Insert some values
mysqli_query($con,"INSERT INTO emp (FirstName)VALUES ('PHP')");
mysqli_query($con,"INSERT INTO emp (FirstName)VALUES ('Java')");
// Commit transaction
mysqli_commit($con);
mysqli_close($con);
?>