4 V5.14 8 Sept 2011 (c) 2000-2011 John Lim (jlim#natsoft.com). All rights reserved.
5 Released under both BSD license and Lesser GPL library license.
6 Whenever there is any discrepancy between the two licenses,
7 the BSD license will take precedence.
10 MySQL code that supports transactions. For MySQL 3.23 or later.
11 Code from James Poon <jpoon88@yahoo.com>
13 Requires mysql client. Works on Windows and Unix.
16 // security - hide paths
17 if (!defined('ADODB_DIR')) die();
19 include_once(ADODB_DIR
."/drivers/adodb-mysql.inc.php");
22 class ADODB_mysqlt
extends ADODB_mysql
{
23 var $databaseType = 'mysqlt';
24 var $ansiOuter = true; // for Version 3.23.17 or later
25 var $hasTransactions = true;
26 var $autoRollback = true; // apparently mysql does not autorollback properly
28 function ADODB_mysqlt()
30 global $ADODB_EXTENSION; if ($ADODB_EXTENSION) $this->rsPrefix
.= 'ext_';
33 /* set transaction mode
35 SET [GLOBAL | SESSION] TRANSACTION ISOLATION LEVEL
36 { READ UNCOMMITTED | READ COMMITTED | REPEATABLE READ | SERIALIZABLE }
39 function SetTransactionMode( $transaction_mode )
41 $this->_transmode
= $transaction_mode;
42 if (empty($transaction_mode)) {
43 $this->Execute('SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ');
46 if (!stristr($transaction_mode,'isolation')) $transaction_mode = 'ISOLATION LEVEL '.$transaction_mode;
47 $this->Execute("SET SESSION TRANSACTION ".$transaction_mode);
52 if ($this->transOff
) return true;
54 $this->Execute('SET AUTOCOMMIT=0');
55 $this->Execute('BEGIN');
59 function CommitTrans($ok=true)
61 if ($this->transOff
) return true;
62 if (!$ok) return $this->RollbackTrans();
64 if ($this->transCnt
) $this->transCnt
-= 1;
65 $ok = $this->Execute('COMMIT');
66 $this->Execute('SET AUTOCOMMIT=1');
67 return $ok ?
true : false;
70 function RollbackTrans()
72 if ($this->transOff
) return true;
73 if ($this->transCnt
) $this->transCnt
-= 1;
74 $ok = $this->Execute('ROLLBACK');
75 $this->Execute('SET AUTOCOMMIT=1');
76 return $ok ?
true : false;
79 function RowLock($tables,$where='',$col='1 as adodbignore')
81 if ($this->transCnt
==0) $this->BeginTrans();
82 if ($where) $where = ' where '.$where;
83 $rs = $this->Execute("select $col from $tables $where for update");
89 class ADORecordSet_mysqlt
extends ADORecordSet_mysql
{
90 var $databaseType = "mysqlt";
92 function ADORecordSet_mysqlt($queryID,$mode=false)
94 if ($mode === false) {
95 global $ADODB_FETCH_MODE;
96 $mode = $ADODB_FETCH_MODE;
101 case ADODB_FETCH_NUM
: $this->fetchMode
= MYSQL_NUM
; break;
102 case ADODB_FETCH_ASSOC
:$this->fetchMode
= MYSQL_ASSOC
; break;
104 case ADODB_FETCH_DEFAULT
:
105 case ADODB_FETCH_BOTH
:
106 default: $this->fetchMode
= MYSQL_BOTH
; break;
109 $this->adodbFetchMode
= $mode;
110 $this->ADORecordSet($queryID);
115 if (@$this->fields
= mysql_fetch_array($this->_queryID
,$this->fetchMode
)) {
116 $this->_currentRow +
= 1;
120 $this->_currentRow +
= 1;
127 class ADORecordSet_ext_mysqlt
extends ADORecordSet_mysqlt
{
129 function ADORecordSet_ext_mysqlt($queryID,$mode=false)
131 if ($mode === false) {
132 global $ADODB_FETCH_MODE;
133 $mode = $ADODB_FETCH_MODE;
137 case ADODB_FETCH_NUM
: $this->fetchMode
= MYSQL_NUM
; break;
138 case ADODB_FETCH_ASSOC
:$this->fetchMode
= MYSQL_ASSOC
; break;
140 case ADODB_FETCH_DEFAULT
:
141 case ADODB_FETCH_BOTH
:
143 $this->fetchMode
= MYSQL_BOTH
; break;
145 $this->adodbFetchMode
= $mode;
146 $this->ADORecordSet($queryID);
151 return adodb_movenext($this);