<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<refentry xml:id="pdo.commit" xmlns="http://docbook.org/ns/docbook">
 <refnamediv>
  <refname>PDO::commit</refname>
  <refpurpose>
   Commits a transaction
  </refpurpose>
 </refnamediv>

 <refsect1 role="description">
  &reftitle.description;
  <methodsynopsis role="PDO">
   <modifier>public</modifier> <type>bool</type><methodname>PDO::commit</methodname>
   <void/>
  </methodsynopsis>
  <para>
   Commits a transaction, returning the database connection to autocommit
   mode until the next call to <methodname>PDO::beginTransaction</methodname>
   starts a new transaction.
  </para>
 </refsect1>

 <refsect1 role="parameters">
  &reftitle.parameters;
  &no.function.parameters;
 </refsect1>

 <refsect1 role="returnvalues">
  &reftitle.returnvalues;
  <para>
   &return.success;
  </para>
 </refsect1>

 <refsect1 role="errors">
  &reftitle.errors;
  <para>
   Throws a <classname>PDOException</classname> if there is no active transaction.
  </para>
  &pdo.errors.exception-not-errmode;
 </refsect1>

 <refsect1 role="examples">
  &reftitle.examples;
  <para>
   <example>
    <title>Committing a basic transaction</title>
    <programlisting role="php">
<![CDATA[
<?php
/* Begin a transaction, turning off autocommit */
$dbh->beginTransaction();

/* Insert multiple records on an all-or-nothing basis */
$sql = 'INSERT INTO fruit
    (name, colour, calories)
    VALUES (?, ?, ?)';

$sth = $dbh->prepare($sql);

foreach ($fruits as $fruit) {
    $sth->execute(array(
        $fruit->name,
        $fruit->colour,
        $fruit->calories,
    ));
}

/* Commit the changes */
$dbh->commit();

/* Database connection is now back in autocommit mode */
?>
]]>
    </programlisting>
   </example>
  </para>
  <para>
   <example>
    <title>Committing a DDL transaction</title>
    <programlisting role="php">
<![CDATA[
<?php
/* Begin a transaction, turning off autocommit */
$dbh->beginTransaction();

/* Change the database schema */
$sth = $dbh->exec("DROP TABLE fruit");

/* Commit the changes */
$dbh->commit();

/* Database connection is now back in autocommit mode */
?>
]]>
    </programlisting>
   </example>
   <note>
    <simpara>
     Not all databases will allow transactions to operate on DDL statements:
     some will generate errors, whereas others (including MySQL) will
     automatically commit the transaction after the first DDL statement has
     been encountered.
    </simpara>
   </note>
  </para>
 </refsect1>

 <refsect1 role="seealso">
  &reftitle.seealso;
  <para>
   <simplelist>
    <member><methodname>PDO::beginTransaction</methodname></member>
    <member><methodname>PDO::rollBack</methodname></member>
    <member><link linkend="pdo.transactions">Transactions and auto-commit</link></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
-->
