/lib/adodb/drivers/adodb-mysqlt.inc.php

https://github.com/markn86/moodle · PHP · 132 lines · 89 code · 20 blank · 23 comment · 16 complexity · 67e3f254e75e962c7515d9eda95af350 MD5 · raw file

  1. <?php
  2. /*
  3. @version v5.21.0 2021-02-27
  4. @copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved.
  5. @copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community
  6. Released under both BSD license and Lesser GPL library license.
  7. Whenever there is any discrepancy between the two licenses,
  8. the BSD license will take precedence.
  9. Set tabs to 8.
  10. This driver only supports the original MySQL driver in transactional mode. It
  11. is deprecated in PHP version 5.5 and removed in PHP version 7. It is deprecated
  12. as of ADOdb version 5.20.0. Use the mysqli driver instead, which supports both
  13. transactional and non-transactional updates
  14. Requires mysql client. Works on Windows and Unix.
  15. */
  16. // security - hide paths
  17. if (!defined('ADODB_DIR')) die();
  18. include_once(ADODB_DIR."/drivers/adodb-mysql.inc.php");
  19. class ADODB_mysqlt extends ADODB_mysql {
  20. var $databaseType = 'mysqlt';
  21. var $ansiOuter = true; // for Version 3.23.17 or later
  22. var $hasTransactions = true;
  23. var $autoRollback = true; // apparently mysql does not autorollback properly
  24. /* set transaction mode
  25. SET [GLOBAL | SESSION] TRANSACTION ISOLATION LEVEL
  26. { READ UNCOMMITTED | READ COMMITTED | REPEATABLE READ | SERIALIZABLE }
  27. */
  28. function SetTransactionMode( $transaction_mode )
  29. {
  30. $this->_transmode = $transaction_mode;
  31. if (empty($transaction_mode)) {
  32. $this->Execute('SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ');
  33. return;
  34. }
  35. if (!stristr($transaction_mode,'isolation')) $transaction_mode = 'ISOLATION LEVEL '.$transaction_mode;
  36. $this->Execute("SET SESSION TRANSACTION ".$transaction_mode);
  37. }
  38. function BeginTrans()
  39. {
  40. if ($this->transOff) return true;
  41. $this->transCnt += 1;
  42. $this->Execute('SET AUTOCOMMIT=0');
  43. $this->Execute('BEGIN');
  44. return true;
  45. }
  46. function CommitTrans($ok=true)
  47. {
  48. if ($this->transOff) return true;
  49. if (!$ok) return $this->RollbackTrans();
  50. if ($this->transCnt) $this->transCnt -= 1;
  51. $ok = $this->Execute('COMMIT');
  52. $this->Execute('SET AUTOCOMMIT=1');
  53. return $ok ? true : false;
  54. }
  55. function RollbackTrans()
  56. {
  57. if ($this->transOff) return true;
  58. if ($this->transCnt) $this->transCnt -= 1;
  59. $ok = $this->Execute('ROLLBACK');
  60. $this->Execute('SET AUTOCOMMIT=1');
  61. return $ok ? true : false;
  62. }
  63. function RowLock($tables,$where='',$col='1 as adodbignore')
  64. {
  65. if ($this->transCnt==0) $this->BeginTrans();
  66. if ($where) $where = ' where '.$where;
  67. $rs = $this->Execute("select $col from $tables $where for update");
  68. return !empty($rs);
  69. }
  70. }
  71. class ADORecordSet_mysqlt extends ADORecordSet_mysql{
  72. var $databaseType = "mysqlt";
  73. function __construct($queryID,$mode=false)
  74. {
  75. if ($mode === false) {
  76. global $ADODB_FETCH_MODE;
  77. $mode = $ADODB_FETCH_MODE;
  78. }
  79. switch ($mode)
  80. {
  81. case ADODB_FETCH_NUM: $this->fetchMode = MYSQL_NUM; break;
  82. case ADODB_FETCH_ASSOC:$this->fetchMode = MYSQL_ASSOC; break;
  83. case ADODB_FETCH_DEFAULT:
  84. case ADODB_FETCH_BOTH:
  85. default: $this->fetchMode = MYSQL_BOTH; break;
  86. }
  87. $this->adodbFetchMode = $mode;
  88. parent::__construct($queryID);
  89. }
  90. function MoveNext()
  91. {
  92. if (@$this->fields = mysql_fetch_array($this->_queryID,$this->fetchMode)) {
  93. $this->_currentRow += 1;
  94. return true;
  95. }
  96. if (!$this->EOF) {
  97. $this->_currentRow += 1;
  98. $this->EOF = true;
  99. }
  100. return false;
  101. }
  102. }
  103. class ADORecordSet_ext_mysqlt extends ADORecordSet_mysqlt {
  104. function MoveNext()
  105. {
  106. return adodb_movenext($this);
  107. }
  108. }