PHP mysqli_autocommit() Function

PHP mysqli_autocommit() turns on or off auto-committing database modifications. To determine the current state of autocommit use the SQL command SELECT @@autocommit.


bool mysqli_autocommit(connection,mode);

mysqli_autocommit() Function Parameter

Connection :Required parameter. The MySQL connection to be used
mode :Required parameter. FALSE turns auto-commit off. TRUE turns auto-commit on.

mysqli_autocommit() Function Return Value

Return Values :Returns TRUE on success or FALSE on failure.

mysqli_autocommit() Function Example

$con = mysqli_connect("localhost","user","password","db");
if (mysqli_connect_errno())
	echo "Failed to connect to MySQL: " . mysqli_connect_error();
mysqli_autocommit($con, FALSE);
$insert_member_sql = "INSERT INTO members (id, username) VALUES('$id', '$username')";
$result = mysqli_query($con, $insert_member_sql);

echo 'Transaction completed successfully!';