PHP mysqli_rollback() Function

Definition

The mysqli_rollback() function rolls back the current transaction for the specified database connection.

Syntax

PHP mysqli_rollback() Function has the following syntax.

Object oriented style

bool mysqli::rollback ([ int $flags [, string $name ]] )

Procedural style

bool mysqli_rollback ( mysqli $link [, int $flags [, string $name ]] )

Parameter

  • link - Procedural style only: A link identifier returned by mysqli_connect() or mysqli_init()
  • flags - A bitmask of MYSQLI_TRANS_COR_* constants.
  • name - If provided then ROLLBACK/*name*/ is executed.

Return

It returns TRUE on success. FALSE on failure.

Example

The mysqli_commit() function commits the current transaction for the specified database connection.

The mysqli_autocommit() function turns on or off auto-committing database.


<?php/*from w w  w.  ja va2 s.com*/
$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 ('Java')");
mysqli_query($con,"INSERT INTO emp (name)VALUES ('PHP')");

// Commit transaction
mysqli_commit($con);

// Rollback transaction
mysqli_rollback($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