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 (method):
$flags
[, string $name
]] )Procedural style:
Begins a transaction. Requires the InnoDB engine (it is enabled by default). For additional details about how MySQL transactions work, see » http://dev.mysql.com/doc/mysql/en/commit.html.
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.
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->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
English translation
You have asked to visit this site in English. For now, only the interface is translated, but not all the content yet.If you want to help me in translations, your contribution is welcome. All you need to do is register on the site, and send me a message asking me to add you to the group of translators, which will give you the opportunity to translate the pages you want. A link at the bottom of each translated page indicates that you are the translator, and has a link to your profile.
Thank you in advance.
Document created the 30/01/2003, last modified the 26/10/2018
Source of the printed document:https://www.gaudry.be/en/php-rf-mysqli.begin-transaction.html
The infobrol is a personal site whose content is my sole responsibility. The text is available under CreativeCommons license (BY-NC-SA). More info on the terms of use and the author.
References
These references and links indicate documents consulted during the writing of this page, or which may provide additional information, but the authors of these sources can not be held responsible for the content of this page.
The author This site is solely responsible for the way in which the various concepts, and the freedoms that are taken with the reference works, are presented here. Remember that you must cross multiple source information to reduce the risk of errors.