PHP mysqli_autocommit() Function
In this chapter you will learn:
- Definition for PHP mysqli_autocommit() Function
- Syntax for PHP mysqli_autocommit() Function
- Parameter for PHP mysqli_autocommit() Function
- Return for PHP mysqli_autocommit() Function
- Related functions
- Example - turns off auto-committing, make some queries, then commit the queries
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//from j av a2s . 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);
?>
Next chapter...
What you will learn in the next chapter:
- Definition for PHP mysqli_change_user() Function
- Syntax for PHP mysqli_change_user() Function
- Parameter for PHP mysqli_change_user() Function
- Return for PHP mysqli_change_user() Function
- Example - changes the user of the specified database connection
Home » PHP Tutorial » PHP MySQLi Functions