xref: /PHP-7.3/ext/pdo/README (revision 1c850bfc)
1PHP Data Objects
2================
3
4Concept: Data Access Abstraction
5
6Goals:
7
81/  Be light-weight
92/  Provide common API for common database operations
103/  Be performant
114/  Keep majority of PHP specific stuff in the PDO core (such as persistent
12    resource management); drivers should only have to worry about getting the
13    data and not about PHP internals.
14
15
16Transactions and autocommit
17===========================
18
19When you create a database handle, you *should* specify the autocommit
20behaviour that you require.  PDO will default to autocommit on.
21
22$dbh = new PDO("...", $user, $pass, array(PDO_ATTR_AUTOCOMMIT => true));
23
24When auto-commit is on, the driver will implicitly commit each query as it is
25executed.  This works fine for most simple tasks but can be significantly
26slower when you are making a large number of udpates.
27
28$dbh = new PDO("...", $user, $pass, array(PDO_ATTR_AUTOCOMMIT => false));
29
30When auto-commit is off, you must then use $dbh->beginTransaction() to
31initiate a transaction.  When your work is done, you then call $dbh->commit()
32or $dbh->rollBack() to persist or abort your changes respectively.  Not all
33databases support transactions.
34
35You can change the auto-commit mode at run-time:
36
37$dbh->setAttribute(PDO_ATTR_AUTOCOMMIT, false);
38
39Regardless of the error handling mode set on the database handle, if the
40autocommit mode cannot be changed, an exception will be thrown.
41
42Some drivers will allow you to temporarily disable autocommit if you call
43$dbh->beginTransaction().  When you commit() or rollBack() such a transaction,
44the handle will switch back to autocommit mode again.  If the mode could not
45be changed, an exception will be raised, as noted above.
46
47When the database handle is closed or destroyed (or at request end for
48persistent handles), the driver will implicitly rollBack().  It is your
49responsibility to call commit() when you are done making changes and
50autocommit is turned off.
51
52vim:tw=78:et
53