update : 2015.11.03
php.shukuma.com

검색:
 
 
Starts a transaction

mysqli::begin_transaction

mysqli_begin_transaction

(PHP 5 >= 5.5.0)

mysqli::begin_transaction -- mysqli_begin_transactionStarts a transaction

설명

객체 기반 형식 (method):

public bool mysqli::begin_transaction ([ int $flags [, string $name ]] )

절차식 형식:

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

Begins a transaction. Requires MySQL 5.6 and above, and 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".

  • MYSQLI_TRANS_START_READ_WRITE: Start the transaction as "START TRANSACTION READ WRITE".

  • 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($linkMYSQLI_TRANS_START_READ_ONLY);

mysqli_query($link"SELECT first_name, last_name FROM actor LIMIT 1");
mysqli_commit($link);

mysqli_close($link);
?>

참고