mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-22 20:08:55 +00:00
136 lines
4.1 KiB
XML
136 lines
4.1 KiB
XML
![]() |
<?xml version="1.0" encoding="utf-8"?>
|
||
|
<!-- $Revision$ -->
|
||
|
<refentry xml:id="function.sqlsrv-commit" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||
|
<refnamediv>
|
||
|
<refname>sqlsrv_commit</refname>
|
||
|
<refpurpose>Commits a transaction that was begun with <function>sqlsrv_begin_transaction</function></refpurpose>
|
||
|
</refnamediv>
|
||
|
<refsect1 role="description">
|
||
|
&reftitle.description;
|
||
|
<methodsynopsis>
|
||
|
<type>bool</type><methodname>sqlsrv_commit</methodname>
|
||
|
<methodparam><type>resource</type><parameter>conn</parameter></methodparam>
|
||
|
</methodsynopsis>
|
||
|
<para>
|
||
|
Commits a transaction that was begun with <function>sqlsrv_begin_transaction</function>.
|
||
|
The connection is returned to auto-commit mode after <function>sqlsrv_commit</function>
|
||
|
is called. The transaction that is committed includes all statements that were
|
||
|
executed after the call to <function>sqlsrv_begin_transaction</function>.
|
||
|
Explicit transactions should be started and committed or rolled back using these
|
||
|
functions instead of executing SQL statements that begin and committ/roll back
|
||
|
transactions. For more information, see
|
||
|
<link xlink:href="&url.sqlsrv.transaction.handling;">SQLSRV Transactions</link>.
|
||
|
</para>
|
||
|
</refsect1>
|
||
|
|
||
|
<refsect1 role="parameters">
|
||
|
&reftitle.parameters;
|
||
|
<para>
|
||
|
<variablelist>
|
||
|
<varlistentry>
|
||
|
<term><parameter>conn</parameter></term>
|
||
|
<listitem>
|
||
|
<para>
|
||
|
The connection on which the transaction is to be committed.
|
||
|
</para>
|
||
|
</listitem>
|
||
|
</varlistentry>
|
||
|
</variablelist>
|
||
|
</para>
|
||
|
</refsect1>
|
||
|
|
||
|
<refsect1 role="returnvalues">
|
||
|
&reftitle.returnvalues;
|
||
|
<para>
|
||
|
&return.success;
|
||
|
</para>
|
||
|
</refsect1>
|
||
|
|
||
|
<refsect1 role="examples">
|
||
|
&reftitle.examples;
|
||
|
<para>
|
||
|
<example>
|
||
|
<title><function>sqlsrv_commit</function> example</title>
|
||
|
<para>
|
||
|
The following example demonstrates how to use <function>sqlsrv_commit</function>
|
||
|
together with <function>sqlsrv_begin_transaction</function> and
|
||
|
<function>sqlsrv_rollback</function>.
|
||
|
</para>
|
||
|
<programlisting role="php">
|
||
|
<![CDATA[
|
||
|
<?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 />";
|
||
|
}
|
||
|
?>
|
||
|
]]>
|
||
|
</programlisting>
|
||
|
</example>
|
||
|
</para>
|
||
|
</refsect1>
|
||
|
|
||
|
<refsect1 role="seealso">
|
||
|
&reftitle.seealso;
|
||
|
<para>
|
||
|
<simplelist>
|
||
|
<member><function>sqlsrv_begin_transaction</function></member>
|
||
|
<member><function>sqlsrv_rollback</function></member>
|
||
|
</simplelist>
|
||
|
</para>
|
||
|
</refsect1>
|
||
|
</refentry>
|
||
|
|
||
|
<!-- Keep this comment at the end of the file
|
||
|
Local variables:
|
||
|
mode: sgml
|
||
|
sgml-omittag:t
|
||
|
sgml-shorttag:t
|
||
|
sgml-minimize-attributes:nil
|
||
|
sgml-always-quote-attributes:t
|
||
|
sgml-indent-step:1
|
||
|
sgml-indent-data:t
|
||
|
indent-tabs-mode:nil
|
||
|
sgml-parent-document:nil
|
||
|
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
|
||
|
sgml-exposed-tags:nil
|
||
|
sgml-local-catalogs:nil
|
||
|
sgml-local-ecat-files:nil
|
||
|
End:
|
||
|
vim600: syn=xml fen fdm=syntax fdl=2 si
|
||
|
vim: et tw=78 syn=sgml
|
||
|
vi: ts=1 sw=1
|
||
|
-->
|