1<?php 2 3/* 4V4.65 22 July 2005 (c) 2000-2005 John Lim (jlim@natsoft.com.my). 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 function BeginTrans() 34 { 35 if ($this->transOff) return true; 36 $this->transCnt += 1; 37 $this->Execute('SET AUTOCOMMIT=0'); 38 $this->Execute('BEGIN'); 39 return true; 40 } 41 42 function CommitTrans($ok=true) 43 { 44 if ($this->transOff) return true; 45 if (!$ok) return $this->RollbackTrans(); 46 47 if ($this->transCnt) $this->transCnt -= 1; 48 $this->Execute('COMMIT'); 49 $this->Execute('SET AUTOCOMMIT=1'); 50 return true; 51 } 52 53 function RollbackTrans() 54 { 55 if ($this->transOff) return true; 56 if ($this->transCnt) $this->transCnt -= 1; 57 $this->Execute('ROLLBACK'); 58 $this->Execute('SET AUTOCOMMIT=1'); 59 return true; 60 } 61 62 function RowLock($tables,$where,$flds='1 as ignore') 63 { 64 if ($this->transCnt==0) $this->BeginTrans(); 65 return $this->GetOne("select $flds from $tables where $where for update"); 66 } 67 68} 69 70class ADORecordSet_mysqlt extends ADORecordSet_mysql{ 71 var $databaseType = "mysqlt"; 72 73 function ADORecordSet_mysqlt($queryID,$mode=false) 74 { 75 if ($mode === false) { 76 global $ADODB_FETCH_MODE; 77 $mode = $ADODB_FETCH_MODE; 78 } 79 80 switch ($mode) 81 { 82 case ADODB_FETCH_NUM: $this->fetchMode = MYSQL_NUM; break; 83 case ADODB_FETCH_ASSOC:$this->fetchMode = MYSQL_ASSOC; break; 84 85 case ADODB_FETCH_DEFAULT: 86 case ADODB_FETCH_BOTH: 87 default: $this->fetchMode = MYSQL_BOTH; break; 88 } 89 90 $this->adodbFetchMode = $mode; 91 $this->ADORecordSet($queryID); 92 } 93 94 function MoveNext() 95 { 96 if (@$this->fields = mysql_fetch_array($this->_queryID,$this->fetchMode)) { 97 $this->_currentRow += 1; 98 return true; 99 } 100 if (!$this->EOF) { 101 $this->_currentRow += 1; 102 $this->EOF = true; 103 } 104 return false; 105 } 106} 107 108class ADORecordSet_ext_mysqlt extends ADORecordSet_mysqlt { 109 110 function ADORecordSet_ext_mysqlt($queryID,$mode=false) 111 { 112 if ($mode === false) { 113 global $ADODB_FETCH_MODE; 114 $mode = $ADODB_FETCH_MODE; 115 } 116 switch ($mode) 117 { 118 case ADODB_FETCH_NUM: $this->fetchMode = MYSQL_NUM; break; 119 case ADODB_FETCH_ASSOC:$this->fetchMode = MYSQL_ASSOC; break; 120 121 case ADODB_FETCH_DEFAULT: 122 case ADODB_FETCH_BOTH: 123 default: 124 $this->fetchMode = MYSQL_BOTH; break; 125 } 126 $this->adodbFetchMode = $mode; 127 $this->ADORecordSet($queryID); 128 } 129 130 function MoveNext() 131 { 132 return adodb_movenext($this); 133 } 134} 135 136?>