sqlsrv_commit

(No version information available, might only be in Git)

sqlsrv_commitCommits a transaction that was begun with sqlsrv_begin_transaction()

说明

sqlsrv_commit ( resource $conn ) : bool

Commits a transaction that was begun with sqlsrv_begin_transaction(). The connection is returned to auto-commit mode after sqlsrv_commit() is called. The transaction that is committed includes all statements that were executed after the call to sqlsrv_begin_transaction(). Explicit transactions should be started and committed or rolled back using these functions instead of executing SQL statements that begin and commit/roll back transactions. For more information, see » SQLSRV Transactions.

参数

conn

The connection on which the transaction is to be committed.

返回值

成功时返回 TRUE, 或者在失败时返回 FALSE

范例

Example #1 sqlsrv_commit() example

The following example demonstrates how to use sqlsrv_commit() together with sqlsrv_begin_transaction() and sqlsrv_rollback().

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

/* Begin the transaction. */
if ( sqlsrv_begin_transaction$conn ) === false ) {
     die( 
print_rsqlsrv_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 />";
}
?>

参见

相关文章
php ibm db2 函数 commits a transactionphp ibm db2 函数 returns the auto generated id of the last insert query that successfully executed on this connectionphp frontbase 函数 commits a transaction to the databasephp firebird/interbase 函数 begin a transactionphp mcve 函数 returns array of strings which represents the keys that can be used for response parameters on this transactionphp mcve 函数 check to see if the transaction was successfulphp maxdb 函数 commits the current transactionphp maxdb 函数 rolls back current transactionphp mysqlnd ms 函数 commits a distributed/xa transaction among mysql serversphp posix 函数 retrieve the error number set by the last posix function that failedphp snmp 函数 return all values that are enums with their enum value instead of the raw integerphp sodium 函数 verifies that the tag is valid for the messagephp sqlsrv 函数 begins a database transactionphp sqlsrv 函数 commits a transaction that was begun with sqlsrv begin transactionphp sqlsrv 函数 opens a connection to a microsoft sql server databasephp sqlsrv 函数 returns error and warning information about the last sqlsrv operation performedphp sqlsrv 函数 rolls back a transaction that was begun with sqlsrv begin transactionphp sqlsrv 函数 returns the number of rows modified by the last insert update or delete query executedphp svn 函数 commits a transaction and returns the new revisionphp win32service 函数 returns the last control message that was sent to this service
关注编程学问公众号