1<?php 2 3/* 4V5.10 10 Nov 2009 (c) 2000-2009 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. 8 Set tabs to 8. 9 10 MySQL code that supports transactions. For MySQL 3.23 or later. 11 Code from James Poon <jpoon88@yahoo.com> 12 13 Requires mysql client. Works on Windows and Unix. 14*/ 15 16// security - hide paths 17if (!defined('ADODB_DIR')) die(); 18 19include_once(ADODB_DIR."/drivers/adodb-mysql.inc.php"); 20 21 22class 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 27 28 function ADODB_mysqlt() 29 { 30 global $ADODB_EXTENSION; if ($ADODB_EXTENSION) $this->rsPrefix .= 'ext_'; 31 } 32 33 /* set transaction mode 34 35 SET [GLOBAL | SESSION] TRANSACTION ISOLATION LEVEL 36{ READ UNCOMMITTED | READ COMMITTED | REPEATABLE READ | SERIALIZABLE } 37 38 */ 39 function SetTransactionMode( $transaction_mode ) 40 { 41 $this->_transmode = $transaction_mode; 42 if (empty($transaction_mode)) { 43 $this->Execute('SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ'); 44 return; 45 } 46 if (!stristr($transaction_mode,'isolation')) $transaction_mode = 'ISOLATION LEVEL '.$transaction_mode; 47 $this->Execute("SET SESSION TRANSACTION ".$transaction_mode); 48 } 49 50 function BeginTrans() 51 { 52 if ($this->transOff) return true; 53 $this->transCnt += 1; 54 $this->Execute('SET AUTOCOMMIT=0'); 55 $this->Execute('BEGIN'); 56 return true; 57 } 58 59 function CommitTrans($ok=true) 60 { 61 if ($this->transOff) return true; 62 if (!$ok) return $this->RollbackTrans(); 63 64 if ($this->transCnt) $this->transCnt -= 1; 65 $ok = $this->Execute('COMMIT'); 66 $this->Execute('SET AUTOCOMMIT=1'); 67 return $ok ? true : false; 68 } 69 70 function RollbackTrans() 71 { 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; 77 } 78 79 function RowLock($tables,$where='',$col='1 as adodb_ignore') 80 { 81 if ($this->transCnt==0) $this->BeginTrans(); 82 if ($where) $where = ' where '.$where; 83 $rs = $this->Execute("select $col from $tables $where for update"); 84 return !empty($rs); 85 } 86 87} 88 89class ADORecordSet_mysqlt extends ADORecordSet_mysql{ 90 var $databaseType = "mysqlt"; 91 92 function ADORecordSet_mysqlt($queryID,$mode=false) 93 { 94 if ($mode === false) { 95 global $ADODB_FETCH_MODE; 96 $mode = $ADODB_FETCH_MODE; 97 } 98 99 switch ($mode) 100 { 101 case ADODB_FETCH_NUM: $this->fetchMode = MYSQL_NUM; break; 102 case ADODB_FETCH_ASSOC:$this->fetchMode = MYSQL_ASSOC; break; 103 104 case ADODB_FETCH_DEFAULT: 105 case ADODB_FETCH_BOTH: 106 default: $this->fetchMode = MYSQL_BOTH; break; 107 } 108 109 $this->adodbFetchMode = $mode; 110 $this->ADORecordSet($queryID); 111 } 112 113 function MoveNext() 114 { 115 if (@$this->fields = mysql_fetch_array($this->_queryID,$this->fetchMode)) { 116 $this->_currentRow += 1; 117 return true; 118 } 119 if (!$this->EOF) { 120 $this->_currentRow += 1; 121 $this->EOF = true; 122 } 123 return false; 124 } 125} 126 127class ADORecordSet_ext_mysqlt extends ADORecordSet_mysqlt { 128 129 function ADORecordSet_ext_mysqlt($queryID,$mode=false) 130 { 131 if ($mode === false) { 132 global $ADODB_FETCH_MODE; 133 $mode = $ADODB_FETCH_MODE; 134 } 135 switch ($mode) 136 { 137 case ADODB_FETCH_NUM: $this->fetchMode = MYSQL_NUM; break; 138 case ADODB_FETCH_ASSOC:$this->fetchMode = MYSQL_ASSOC; break; 139 140 case ADODB_FETCH_DEFAULT: 141 case ADODB_FETCH_BOTH: 142 default: 143 $this->fetchMode = MYSQL_BOTH; break; 144 } 145 $this->adodbFetchMode = $mode; 146 $this->ADORecordSet($queryID); 147 } 148 149 function MoveNext() 150 { 151 return adodb_movenext($this); 152 } 153} 154 155?>