PHP Tutorial - PHP mysqli_commit() Function






Definition

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

Syntax

PHP mysqli_commit() Function has the following syntax.

mysqli_commit(connection);

Parameter

ParameterIs RequiredDescription
connectionRequired.MySQL connection

Return

It returns TRUE on success or FALSE on failure.

Example

The following code turns off auto-committing, makes some queries, then commits the queries.


<?php/* ww  w .ja va  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 (name)VALUES ('A')");
mysqli_query($con,"INSERT INTO emp (name)VALUES ('B')");
mysqli_query($con,"INSERT INTO emp (name)VALUES ('C')");
mysqli_query($con,"INSERT INTO emp (name)VALUES ('D')");

// Commit transaction
mysqli_commit($con);

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