PHP mysqli_commit() Function
Definition
The mysqli_commit() function commits the current transaction for the specified database connection.
Syntax
PHP mysqli_commit() Function has the following syntax.
mysqli_commit(connection);
Parameter
Parameter | Is Required | Description |
---|---|---|
connection | Required. | MySQL connection |
Return
It returns TRUE on success or FALSE on failure.
Example
The following code turns off auto-committing, makes some queries, then commits the queries.
<?php//from w w w. j a v a2 s .c om
$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 (name)VALUES ('A')");
mysqli_query($con,"INSERT INTO emp (name)VALUES ('B')");
mysqli_query($con,"INSERT INTO emp (name)VALUES ('C')");
mysqli_query($con,"INSERT INTO emp (name)VALUES ('D')");
// Commit transaction
mysqli_commit($con);
// Close connection
mysqli_close($con);
?>