Starts a transaction (original) (raw)
mysqli::begin_transaction
mysqli_begin_transaction
(PHP 5 >= 5.5.0, PHP 7)
mysqli::begin_transaction -- mysqli_begin_transaction — Starts a transaction
Description
Object oriented style
public mysqli::begin_transaction ([ int $flags
= 0 [, string $name
]] ) : bool
mysqli_begin_transaction ( mysqli $link
[, int $flags
= 0 [, string $name
]] ) : bool
Parameters
link
Procedural style only: A link identifier returned by mysqli_connect() or mysqli_init()
flags
Valid flags are:
MYSQLI_TRANS_START_READ_ONLY
: Start the transaction as "START TRANSACTION READ ONLY". Requires MySQL 5.6 and above.MYSQLI_TRANS_START_READ_WRITE
: Start the transaction as "START TRANSACTION READ WRITE". Requires MySQL 5.6 and above.MYSQLI_TRANS_START_WITH_CONSISTENT_SNAPSHOT
: Start the transaction as "START TRANSACTION WITH CONSISTENT SNAPSHOT".
name
Savepoint name for the transaction.
Return Values
Returns TRUE
on success or FALSE
on failure.
Examples
Example #1 $mysqli->begin_transaction() example
Object oriented style
`<?php
$mysqli = new mysqli("127.0.0.1", "my_user", "my_password", "sakila");
if (
$mysqli->connect_errno) {
printf("Connect failed: %s\n", $mysqli->connect_error);
exit();
}$mysqli->begin_transaction(MYSQLI_TRANS_START_READ_ONLY);$mysqli->query("SELECT first_name, last_name FROM actor"); mysqli−>commit();mysqli->commit();mysqli−>commit();mysqli->close();
?> `
Procedural style
`<?php
$link = mysqli_connect("127.0.0.1", "my_user", "my_password", "sakila");
if (
mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}mysqli_begin_transaction($link, MYSQLI_TRANS_START_READ_ONLY);mysqli_query($link, "SELECT first_name, last_name FROM actor LIMIT 1");
mysqli_commit($link);mysqli_close($link);
?> `
See Also
- mysqli_autocommit() - Turns on or off auto-committing database modifications
- mysqli_commit() - Commits the current transaction
- mysqli_rollback() - Rolls back current transaction