/
commit.xml
138 lines (122 loc) · 3.11 KB
/
commit.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<?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>
<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 <function>PDO::beginTransaction</function>
starts a new transaction.
</para>
</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><function>PDO::beginTransaction</function></member>
<member><function>PDO::rollBack</function></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
-->