mysqli::close
mysqli::$connect_errno
mysqli
PHP Manual

# mysqli::commit

# mysqli_commit

(PHP 5)

mysqli::commit -- mysqli_commit — Commits the current transaction

### Description

Object oriented style

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

Procedural style

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

Commits the current transaction for the database connection.

### Parameters

`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 COMMIT/*name*/ is executed.

### Return Values

Returns `TRUE` on success or `FALSE` on failure.

### Changelog

Version | Description
--- | ---
5.5.0 | Added `flags` and `name` parameters.

### Examples

Example #1 mysqli::commit() example

Object oriented style

`<?php
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$mysqli->query("CREATE TABLE Language LIKE CountryLanguage");
/* set autocommit to off */
$mysqli->autocommit(FALSE);
/* Insert some values */
$mysqli->query("INSERT INTO Language VALUES ('DEU', 'Bavarian', 'F', 11.2)");
$mysqli->query("INSERT INTO Language VALUES ('DEU', 'Swabian', 'F', 9.4)");
/* commit transaction */
$mysqli->commit();
/* drop table */
$mysqli->query("DROP TABLE Language");
/* close connection */
$mysqli->close();
?>`

Procedural style

`<?php
$link = mysqli_connect("localhost", "my_user", "my_password", "test");
/* check connection */
if (!$link) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
/* set autocommit to off */
mysqli_autocommit($link, FALSE);
mysqli_query($link, "CREATE TABLE Language LIKE CountryLanguage");
/* Insert some values */
mysqli_query($link, "INSERT INTO Language VALUES ('DEU', 'Bavarian', 'F', 11.2)");
mysqli_query($link, "INSERT INTO Language VALUES ('DEU', 'Swabian', 'F', 9.4)");
/* commit transaction */
mysqli_commit($link);
/* close connection */
mysqli_close($link);
?>`

### See Also

- mysqli_autocommit() - Turns on or off auto-committing database modifications
- mysqli_begin_transaction() - Starts a transaction
- mysqli_rollback() - Rolls back current transaction
- mysqli_savepoint() - Set a named transaction savepoint

mysqli::close
mysqli::$connect_errno
mysqli
PHP Manual