(PHP 5 >= 5.5.0, PHP 7)
mysqli::begin_transaction -- mysqli_begin_transaction — Starts a transaction
锟斤拷锟斤拷锟斤拷锟斤拷锟� (method):
$flags
= 0
[, string $name
]] ) : bool锟斤拷锟教伙拷锟斤拷锟�:
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.
link
锟斤拷锟皆癸拷锟教伙拷锟斤拷式锟斤拷锟斤拷mysqli_connect() 锟斤拷 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.
锟缴癸拷时锟斤拷锟斤拷 TRUE
锟斤拷 锟斤拷锟斤拷锟斤拷失锟斤拷时锟斤拷锟斤拷 FALSE
锟斤拷
Example #1 $mysqli->begin_transaction() example
锟斤拷锟斤拷锟斤拷锟斤拷锟�
<?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();
?>
锟斤拷锟教伙拷锟斤拷锟�
<?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);
?>