sqlsrv_rollback

(사용 가능한 버전 정보가 없으며 Git에만 있을 수 있음)

sqlsrv_rollback — sqlsrv_begin_transaction()으로 시작된 트랜잭션을 롤백합니다.

sqlsrv_rollback(resource $conn): bool

sqlsrv_begin_transaction()으로 시작된 트랜잭션을 롤백하고 연결을 자동 커밋 모드로 반환합니다.


매개변수

conn
sqlsrv_connect() 호출에 의해 반환된 연결 리소스입니다.

반환 값

성공하면 true를, 실패하면 false를 반환합니다.


Examples

예제 #1 sqlsrv_rollback() 예제

다음 예에서는 sqlsrv_commit()sqlsrv_rollback()과 함께 sqlsrv_begin_transaction()을 사용하는 방법을 보여줍니다.

                  
<?php
$serverName = "serverName\sqlexpress";
$connectionInfo = array( "Database"=>"dbName", "UID"=>"userName", "PWD"=>"password");
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn === false ) {
    die( print_r( sqlsrv_errors(), true ));
}

/* Begin the transaction. */
if ( sqlsrv_begin_transaction( $conn ) === false ) {
     die( print_r( sqlsrv_errors(), true ));
}

/* Initialize parameter values. */
$orderId = 1; $qty = 10; $productId = 100;

/* Set up and execute the first query. */
$sql1 = "INSERT INTO OrdersTable (ID, Quantity, ProductID)
         VALUES (?, ?, ?)";
$params1 = array( $orderId, $qty, $productId );
$stmt1 = sqlsrv_query( $conn, $sql1, $params1 );

/* Set up and execute the second query. */
$sql2 = "UPDATE InventoryTable
         SET Quantity = (Quantity - ?)
         WHERE ProductID = ?";
$params2 = array($qty, $productId);
$stmt2 = sqlsrv_query( $conn, $sql2, $params2 );

/* If both queries were successful, commit the transaction. */
/* Otherwise, rollback the transaction. */
if( $stmt1 && $stmt2 ) {
     sqlsrv_commit( $conn );
     echo "Transaction committed.<br />";
} else {
     sqlsrv_rollback( $conn );
     echo "Transaction rolled back.<br />";
}
?>
                  
                

기타