PHP mysqli_commit() Function
In this chapter you will learn:
- Definition for PHP mysqli_commit() Function
- Syntax for PHP mysqli_commit() Function
- Parameter for PHP mysqli_commit() Function
- Return for PHP mysqli_commit() Function
- Example - turns off auto-committing, makes some queries, then commits the queries
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//j a va2 s .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 (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);
?>
Next chapter...
What you will learn in the next chapter:
- Definition for PHP mysqli_connect() Function
- Syntax for PHP mysqli_connect() Function
- Parameter for PHP mysqli_connect() Function
- Return for PHP mysqli_connect() Function
- Example - opens a new connection to the MySQL server
Home » PHP Tutorial » PHP MySQLi Functions