Turn off auto-committing, make some queries, commit the queries, then roll back the current transaction in PHP

Description

The following code shows how to turn off auto-committing, make some queries, commit the queries, then roll back the current transaction.

Example


/*  w  ww. ja  v a 2 s.c  o  m*/
<?php
    $con=mysqli_connect("localhost","root","","test");
    // Check connection
    if (mysqli_connect_errno()){
      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 employee(Name)VALUES ('XML')");
    mysqli_query($con,"INSERT INTO employee(Name)VALUES ('CSS')");

    // Commit transaction
    mysqli_commit($con);

    // Rollback transaction
    mysqli_rollback($con);

    // Close connection
    mysqli_close($con);
?>




















Home »
  PHP Tutorial »
    MySQL »




MySQLi
MySQLi Object Oriented