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

ParameterIs RequiredDescription
connectionRequired.MySQL connection
modeRequired.FALSE turns auto-commit off. TRUE turns auto-commit on

Return

It returns TRUE on success or FALSE on failure.

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);
?>




















Home »
  PHP Tutorial »
    Function reference »




PHP Array Functions
PHP Calendar Functions
PHP Class Functions
PHP Data Type Functions
PHP Date Functions
PHP File Functions
PHP Image Functions
PHP Math Functions
PHP MySQLi Functions
PHP SimpleXML Functions
PHP String Functions
PHP XML Functions
PHP Zip Functions