ADOdb

Database Abstraction Layer for PHP

User Tools

Site Tools


v5:reference:connection:transcnt

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

v5:reference:connection:transcnt [2016/04/14 15:56] (current)
mnewnham created
Line 1: Line 1:
 +====== transCnt ======
 +~~NOTOC~~
 +<WRAP right box>
 +== Syntax ==
 +  int ADOconnection::transCnt
 +</WRAP>
 +===== Description =====
 +The value of ''$db->transCnt'' returns the current transaction nesting level. If no transaction has been started, the value is zero. 
  
 +For **//granular//** transaction handling:
 +  * The value is always 1 when a transaction has been started, as nested transactions are not permitted.
 +
 +For **//smart//** transaction handling:
 +  * The value indicates the nesting level of smart transactions. You should not modify the value of this variable manually, as this will likely cause a transaction scope failure. 
 +
 +You can check the value of transCnt to see if a transaction has been started. This is useful in, for example, loadable classes where the start point of a transaction might be in a different procedure.
 + 
 +===== Usage =====
 +<code php>
 +
 +if ($db->transCnt == 0)
 +    $db->startTrans();
 +
 +/*
 +* transCnt is now 1 Do some work
 +*/
 +$db->startTrans();
 +
 +/*
 +* transCnt is now 2
 +*/
 +$db->execute('some insert statement...');
 +
 +
 +/*
 +* Because the transCnt > 1, the completeTrans is ignored 
 +*/
 +$db->completeTrans();
 +
 +/*
 +* transCnt is now 0, complete the transaction
 +*/
 +$db->completeTrans()
 +</code>
v5/reference/connection/transcnt.txt ยท Last modified: 2016/04/14 15:56 by mnewnham