PHP.mk документација

mysqli::begin_transaction

Почист и полокален преглед на PHP референцата, со задржана структура од PHP.net и подобра читливост за примери, секции и белешки.

mysqli.begin-transaction.php PHP.net прокси Преводот се освежува
Оригинал на PHP.net
Патека mysqli.begin-transaction.php Локална патека за оваа страница.
Извор php.net/manual/en Оригиналниот HTML се реупотребува и локално се стилизира.
Режим Прокси + превод во позадина Кодовите, табелите и белешките остануваат читливи во истиот тек.
mysqli::begin_transaction

Референца за `mysqli.begin-transaction.php` со подобрена типографија и навигација.

mysqli.begin-transaction.php

mysqli::begin_transaction

mysqli_begin_transaction

Распакување на вгнездени низи

mysqli::begin_transaction -- mysqli_begin_transactionStarts a transaction

= NULL

Напиши целосна ознака на елемент

public mysqli::begin_transaction(int $flags = 0, ?string $name = null): bool

Објектно-ориентиран стил (метод):

mysqli_begin_transaction(mysqli $mysql, int $flags = 0, ?string $name = null): bool

Започнува трансакција » http://dev.mysql.com/doc/mysql/en/commit.html.

Параметри

mysql

објектот како свој прв аргумент. mysqli Само процедурален стил: А mysqli_connect() or mysqli_init()

flags

Добива информации за статусот на даденото

  • MYSQLI_TRANS_START_READ_ONLYЗапочнува трансакција. Потребен е InnoDB енџинот (вклучен е по дифолт). За дополнителни детали за тоа како функционираат MySQL трансакциите, видете

  • MYSQLI_TRANS_START_READ_WRITE: Започнете ја трансакцијата како "START TRANSACTION READ ONLY". Потребен е MySQL 5.6 и погоре.

  • MYSQLI_TRANS_START_WITH_CONSISTENT_SNAPSHOT: Започнете ја трансакцијата како "START TRANSACTION READ WRITE". Потребен е MySQL 5.6 и погоре.

name

: Започнете ја трансакцијата како "START TRANSACTION WITH CONSISTENT SNAPSHOT".

Вратени вредности

Патеката до PHP скриптата што треба да се провери. true на успех или false при неуспех.

Дневник на промени

Верзија = NULL
8.0.0 name сега е null.

Примери

Пример #1 се извршува. example

Напиши целосна ознака на елемент

<?php

/* Tell mysqli to throw an exception if an error occurs */
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);

$mysqli = new mysqli("localhost", "my_user", "my_password", "world");

/* The table engine has to support transactions */
$mysqli->query("CREATE TABLE IF NOT EXISTS language (
Code text NOT NULL,
Speakers int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;"
);

/* Start transaction */
$mysqli->begin_transaction();

try {
/* Insert some values */
$mysqli->query("INSERT INTO language(Code, Speakers) VALUES ('DE', 42000123)");

/* Try to insert invalid values */
$language_code = 'FR';
$native_speakers = 'Unknown';
$stmt = $mysqli->prepare('INSERT INTO language(Code, Speakers) VALUES (?,?)');
$stmt->bind_param('ss', $language_code, $native_speakers);
$stmt->execute();

/* If code reaches this point without errors then commit the data in the database */
$mysqli->commit();
} catch (
mysqli_sql_exception $exception) {
$mysqli->rollback();

throw
$exception;
}

Процедурален стил

<?php

/* Tell mysqli to throw an exception if an error occurs */
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);

$mysqli = mysqli_connect("localhost", "my_user", "my_password", "world");

/* The table engine has to support transactions */
mysqli_query($mysqli, "CREATE TABLE IF NOT EXISTS language (
Code text NOT NULL,
Speakers int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;"
);

/* Start transaction */
mysqli_begin_transaction($mysqli);

try {
/* Insert some values */
mysqli_query($mysqli, "INSERT INTO language(Code, Speakers) VALUES ('DE', 42000123)");

/* Try to insert invalid values */
$language_code = 'FR';
$native_speakers = 'Unknown';
$stmt = mysqli_prepare($mysqli, 'INSERT INTO language(Code, Speakers) VALUES (?,?)');
mysqli_stmt_bind_param($stmt, 'ss', $language_code, $native_speakers);
mysqli_stmt_execute($stmt);

/* If code reaches this point without errors then commit the data in the database */
mysqli_commit($mysqli);
} catch (
mysqli_sql_exception $exception) {
mysqli_rollback($mysqli);

throw
$exception;
}

Белешки

Забелешка:

mysqli::begin_transaction()

Види Исто така

Белешки од корисници 2 забелешки

Име на точката за зачувување за трансакцијата.
пред 7 години
If you receive errors like: "This server version doesn't support 'READ WRITE' and 'READ ONLY'. Minimum 5.6.5 is required" with versions of MariaDB that DO support them, this is due to an internal check in mysqli conflicting with a hack in MariaDB to allow replication with oracle mysql.

MariaDB prefixes its server version numbers with "5.5.5-" for example "5.5.5-10.3.7-MariaDB-1:10.3.7+maria~stretch". This is because oracle mysql would interpet the "10" as version 1. Mysql clients aware of MariaDB have been updated to detect and strip this prefix.

However the check for mysqli.begin-transaction sees the 5.5.5 prefix and so fails.

The workaround is to specify a custom version string without the prefix for MariaDB on the command line using the --version option. Then mysqli.begin-transaction functions as expected.
PHP Гуру
пред 5 години
MySQL 5.6 introduces READ ONLY mode which applies optimizations to your transactions that can only be applied when it knows in advance that no table modifications will be made and that no locks will be issued.

The default access mode is READ WRITE in all versions up to and including MySQL 5.6. Starting in MySQL 5.7, the appropriate access mode is detected automatically. So if your transaction attempts modifications or table locks, it will automatically use READ WRITE mode, otherwise it will use READ ONLY mode and your transaction will benefit from the optimizations that come from that without having to explicitly declare is as READ ONLY.

Therefore the only time you need to explicitly declare an access mode is when you are using MySQL 5.6 and you are sure that you want READ ONLY mode. Note that any queries that attempt to modify tables or issue locks in READ ONLY mode will fail. Temporary tables can still be modified.

(Moderators. This post should replace the previous post that I made on the subject. Thanks.)
На оваа страница

Автоматски outline од активната документација.

Насловите ќе се појават тука по вчитување.

Попрегледно читање

Примерите, changelog табелите и user notes се визуелно издвоени за да не се губат во долгата содржина.

Брз совет Користи го outline-от Скокни директно на главните секции од активната страница.
Извор Оригиналниот линк останува достапен Кога ти треба целосен upstream context, отвори го PHP.net во нов tab.