Skip to content

Commit a940503

Browse files
committed
[docs] add DB nested transaction
1 parent febc03a commit a940503

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

user_guide_src/source/database/transactions.rst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,18 @@ If you would like to run transactions manually you can do so as follows:
9797

9898
.. note:: Make sure to use ``$this->db->transBegin()`` when running manual
9999
transactions, **NOT** ``$this->db->transStart()``.
100+
101+
Nested Transactions
102+
===================
103+
104+
In CodeIgniter, transactions can be nested in a way such that only the
105+
outmost or top-level transaction commands are executed. You can include as
106+
many pairs of ``transStart``/``transComplete`` or ``transBegin``/``transCommit``/``transRollback``
107+
as you want inside a transaction block and so on. CodeIgniter will keep
108+
track of the transaction "depth" and only take action at the outermost layer
109+
(zero depth).
110+
111+
.. literalinclude:: transactions/007.php
112+
113+
.. note:: Use this technique ONLY IF you actually know what you are doing.
114+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
$this->db->transStart(); // actually starts a transaction
4+
$this->db->query('SOME QUERY 1 ...');
5+
$this->db->transStart(); // doesn't necessarily start another transaction
6+
$this->db->query('SOME QUERY 2 ...');
7+
$this->db->transComplete(); // doesn't necessarily end the transaction, but required to finish the inner transaction
8+
$this->db->query('SOME QUERY 3 ...');
9+
$this->db->transComplete(); // actually ends the transaction

0 commit comments

Comments
 (0)