[ Index ] |
|
Code source de CMS made simple 1.0.5 |
1 <?php 2 /** 3 * ADOdb Lite Transaction Module for Mysqli 4 * 5 */ 6 7 eval('class mysqli_transaction_EXTENDER extends '. $last_module . '_ADOConnection { }'); 8 9 class mysqli_transaction_ADOConnection extends mysqli_transaction_EXTENDER 10 { 11 var $autoCommit = true; 12 var $transOff = 0; 13 var $transCnt = 0; 14 var $transaction_status = true; 15 16 function StartTrans($errfn = 'ADODB_TransMonitor') 17 { 18 if ($this->transOff > 0) { 19 $this->transOff += 1; 20 return; 21 } 22 $this->transaction_status = true; 23 24 if ($this->debug && $this->transCnt > 0) 25 ADOConnection::outp("Bad Transaction: StartTrans called within BeginTrans"); 26 27 $this->BeginTrans(); 28 $this->transOff = 1; 29 } 30 31 function BeginTrans() 32 { 33 if ($this->transOff) 34 return true; 35 36 $this->transCnt += 1; 37 $this->Execute('SET AUTOCOMMIT=0'); 38 $this->Execute('BEGIN'); 39 return true; 40 } 41 42 function CompleteTrans($autoComplete = true) 43 { 44 if ($this->transOff > 1) { 45 $this->transOff -= 1; 46 return true; 47 } 48 $this->transOff = 0; 49 if ($this->transaction_status && $autoComplete) { 50 if (!$this->CommitTrans()) { 51 $this->transaction_status = false; 52 if ($this->debug) 53 ADOConnection::outp("Smart Commit failed"); 54 } else 55 if ($this->debug) 56 ADOConnection::outp("Smart Commit occurred"); 57 } else { 58 $this->RollbackTrans(); 59 if ($this->debug) 60 ADOCOnnection::outp("Smart Rollback occurred"); 61 } 62 return $this->transaction_status; 63 } 64 65 function CommitTrans($ok=true) 66 { 67 if ($this->transOff) 68 return true; 69 70 if (!$ok) return 71 $this->RollbackTrans(); 72 73 if ($this->transCnt) 74 $this->transCnt -= 1; 75 76 $this->Execute('COMMIT'); 77 $this->Execute('SET AUTOCOMMIT=1'); 78 return true; 79 } 80 81 function RollbackTrans() 82 { 83 if ($this->transOff) 84 return true; 85 86 if ($this->transCnt) 87 $this->transCnt -= 1; 88 89 $this->Execute('ROLLBACK'); 90 $this->Execute('SET AUTOCOMMIT=1'); 91 return true; 92 } 93 94 function FailTrans() 95 { 96 if ($this->debug) 97 if ($this->transOff == 0) { 98 ADOConnection::outp("FailTrans outside StartTrans/CompleteTrans"); 99 } else { 100 ADOConnection::outp("FailTrans was called"); 101 } 102 $this->transaction_status = false; 103 } 104 105 function HasFailedTrans() 106 { 107 if ($this->transOff > 0) 108 return $this->transaction_status == false; 109 110 return false; 111 } 112 113 function RowLock($tables,$where,$flds='1 as ignore') 114 { 115 if ($this->transCnt==0) 116 $this->BeginTrans(); 117 118 return $this->GetOne("select $flds from $tables where $where for update"); 119 } 120 121 function CommitLock($table) 122 { 123 return $this->CommitTrans(); 124 } 125 126 function RollbackLock($table) 127 { 128 return $this->RollbackTrans(); 129 } 130 131 } 132 133 eval('class mysqli_transaction_resultset_EXTENDER extends '. $last_module . '_ResultSet { }'); 134 135 class mysqli_transaction_ResultSet extends mysqli_transaction_resultset_EXTENDER 136 { 137 } 138 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Tue Apr 3 18:50:37 2007 | par Balluche grâce à PHPXref 0.7 |