PageRenderTime 52ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 1ms

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

https://github.com/michaeljoyce/pkp-lib
PHP | 805 lines | 625 code | 115 blank | 65 comment | 127 complexity | 046a97ced476903ea0940bed27da2e78 MD5 | raw file
Possible License(s): LGPL-2.1, BSD-3-Clause
  1. <?php
  2. /*
  3. V4.90 8 June 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
  4. Released under both BSD license and Lesser GPL library license.
  5. Whenever there is any discrepancy between the two licenses,
  6. the BSD license will take precedence.
  7. Set tabs to 8.
  8. MySQL code that does not support transactions. Use mysqlt if you need transactions.
  9. Requires mysql client. Works on Windows and Unix.
  10. 28 Feb 2001: MetaColumns bug fix - suggested by Freek Dijkstra (phpeverywhere@macfreek.com)
  11. */
  12. // security - hide paths
  13. if (!defined('ADODB_DIR')) die();
  14. if (! defined("_ADODB_MYSQL_LAYER")) {
  15. define("_ADODB_MYSQL_LAYER", 1 );
  16. class ADODB_mysql extends ADOConnection {
  17. var $databaseType = 'mysql';
  18. var $dataProvider = 'mysql';
  19. var $hasInsertID = true;
  20. var $hasAffectedRows = true;
  21. var $metaTablesSQL = "SHOW TABLES";
  22. var $metaColumnsSQL = "SHOW COLUMNS FROM %s";
  23. var $fmtTimeStamp = "'Y-m-d H:i:s'";
  24. var $hasLimit = true;
  25. var $hasMoveFirst = true;
  26. var $hasGenID = true;
  27. var $isoDates = true; // accepts dates in ISO format
  28. var $sysDate = 'CURDATE()';
  29. var $sysTimeStamp = 'NOW()';
  30. var $hasTransactions = false;
  31. var $forceNewConnect = false;
  32. var $poorAffectedRows = true;
  33. var $clientFlags = 0;
  34. var $substr = "substring";
  35. var $nameQuote = '`'; /// string to use to quote identifiers and names
  36. var $compat323 = false; // true if compat with mysql 3.23
  37. function ADODB_mysql()
  38. {
  39. if (defined('ADODB_EXTENSION')) $this->rsPrefix .= 'ext_';
  40. }
  41. function ServerInfo()
  42. {
  43. $arr['description'] = ADOConnection::GetOne("select version()");
  44. $arr['version'] = ADOConnection::_findvers($arr['description']);
  45. return $arr;
  46. }
  47. function IfNull( $field, $ifNull )
  48. {
  49. return " IFNULL($field, $ifNull) "; // if MySQL
  50. }
  51. function &MetaTables($ttype=false,$showSchema=false,$mask=false)
  52. {
  53. $save = $this->metaTablesSQL;
  54. if ($showSchema && is_string($showSchema)) {
  55. $this->metaTablesSQL .= " from $showSchema";
  56. }
  57. if ($mask) {
  58. $mask = $this->qstr($mask);
  59. $this->metaTablesSQL .= " like $mask";
  60. }
  61. $ret =& ADOConnection::MetaTables($ttype,$showSchema);
  62. $this->metaTablesSQL = $save;
  63. return $ret;
  64. }
  65. function &MetaIndexes ($table, $primary = FALSE, $owner=false)
  66. {
  67. // save old fetch mode
  68. global $ADODB_FETCH_MODE;
  69. $false = false;
  70. $save = $ADODB_FETCH_MODE;
  71. $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
  72. if ($this->fetchMode !== FALSE) {
  73. $savem = $this->SetFetchMode(FALSE);
  74. }
  75. // get index details
  76. $rs = $this->Execute(sprintf('SHOW INDEX FROM %s',$table));
  77. // restore fetchmode
  78. if (isset($savem)) {
  79. $this->SetFetchMode($savem);
  80. }
  81. $ADODB_FETCH_MODE = $save;
  82. if (!is_object($rs)) {
  83. return $false;
  84. }
  85. $indexes = array ();
  86. // parse index data into array
  87. while ($row = $rs->FetchRow()) {
  88. if ($primary == FALSE AND $row[2] == 'PRIMARY') {
  89. continue;
  90. }
  91. if (!isset($indexes[$row[2]])) {
  92. $indexes[$row[2]] = array(
  93. 'unique' => ($row[1] == 0),
  94. 'columns' => array()
  95. );
  96. }
  97. $indexes[$row[2]]['columns'][$row[3] - 1] = $row[4];
  98. }
  99. // sort columns by order in the index
  100. foreach ( array_keys ($indexes) as $index )
  101. {
  102. ksort ($indexes[$index]['columns']);
  103. }
  104. return $indexes;
  105. }
  106. // if magic quotes disabled, use mysql_real_escape_string()
  107. function qstr($s,$magic_quotes=false)
  108. {
  109. if (!$magic_quotes) {
  110. if (ADODB_PHPVER >= 0x4300) {
  111. if (is_resource($this->_connectionID))
  112. return "'".mysql_real_escape_string($s,$this->_connectionID)."'";
  113. }
  114. if ($this->replaceQuote[0] == '\\'){
  115. $s = adodb_str_replace(array('\\',"\0"),array('\\\\',"\\\0"),$s);
  116. }
  117. return "'".str_replace("'",$this->replaceQuote,$s)."'";
  118. }
  119. // undo magic quotes for "
  120. $s = str_replace('\\"','"',$s);
  121. return "'$s'";
  122. }
  123. function _insertid()
  124. {
  125. return ADOConnection::GetOne('SELECT LAST_INSERT_ID()');
  126. //return mysql_insert_id($this->_connectionID);
  127. }
  128. function GetOne($sql,$inputarr=false)
  129. {
  130. if ($this->compat323 == false && strncasecmp($sql,'sele',4) == 0) {
  131. $rs =& $this->SelectLimit($sql,1,-1,$inputarr);
  132. if ($rs) {
  133. $rs->Close();
  134. if ($rs->EOF) return false;
  135. return reset($rs->fields);
  136. }
  137. } else {
  138. return ADOConnection::GetOne($sql,$inputarr);
  139. }
  140. return false;
  141. }
  142. function BeginTrans()
  143. {
  144. if ($this->debug) ADOConnection::outp("Transactions not supported in 'mysql' driver. Use 'mysqlt' or 'mysqli' driver");
  145. }
  146. function _affectedrows()
  147. {
  148. return mysql_affected_rows($this->_connectionID);
  149. }
  150. // See http://www.mysql.com/doc/M/i/Miscellaneous_functions.html
  151. // Reference on Last_Insert_ID on the recommended way to simulate sequences
  152. var $_genIDSQL = "update %s set id=LAST_INSERT_ID(id+1);";
  153. var $_genSeqSQL = "create table %s (id int not null)";
  154. var $_genSeq2SQL = "insert into %s values (%s)";
  155. var $_dropSeqSQL = "drop table %s";
  156. function CreateSequence($seqname='adodbseq',$startID=1)
  157. {
  158. if (empty($this->_genSeqSQL)) return false;
  159. $u = strtoupper($seqname);
  160. $ok = $this->Execute(sprintf($this->_genSeqSQL,$seqname));
  161. if (!$ok) return false;
  162. return $this->Execute(sprintf($this->_genSeq2SQL,$seqname,$startID-1));
  163. }
  164. function GenID($seqname='adodbseq',$startID=1)
  165. {
  166. // post-nuke sets hasGenID to false
  167. if (!$this->hasGenID) return false;
  168. $savelog = $this->_logsql;
  169. $this->_logsql = false;
  170. $getnext = sprintf($this->_genIDSQL,$seqname);
  171. $holdtransOK = $this->_transOK; // save the current status
  172. $rs = @$this->Execute($getnext);
  173. if (!$rs) {
  174. if ($holdtransOK) $this->_transOK = true; //if the status was ok before reset
  175. $u = strtoupper($seqname);
  176. $this->Execute(sprintf($this->_genSeqSQL,$seqname));
  177. $this->Execute(sprintf($this->_genSeq2SQL,$seqname,$startID-1));
  178. $rs = $this->Execute($getnext);
  179. }
  180. $this->genID = mysql_insert_id($this->_connectionID);
  181. if ($rs) $rs->Close();
  182. $this->_logsql = $savelog;
  183. return $this->genID;
  184. }
  185. function &MetaDatabases()
  186. {
  187. $qid = mysql_list_dbs($this->_connectionID);
  188. $arr = array();
  189. $i = 0;
  190. $max = mysql_num_rows($qid);
  191. while ($i < $max) {
  192. $db = mysql_tablename($qid,$i);
  193. if ($db != 'mysql') $arr[] = $db;
  194. $i += 1;
  195. }
  196. return $arr;
  197. }
  198. // Format date column in sql string given an input format that understands Y M D
  199. function SQLDate($fmt, $col=false)
  200. {
  201. if (!$col) $col = $this->sysTimeStamp;
  202. $s = 'DATE_FORMAT('.$col.",'";
  203. $concat = false;
  204. $len = strlen($fmt);
  205. for ($i=0; $i < $len; $i++) {
  206. $ch = $fmt[$i];
  207. switch($ch) {
  208. default:
  209. if ($ch == '\\') {
  210. $i++;
  211. $ch = substr($fmt,$i,1);
  212. }
  213. /** FALL THROUGH */
  214. case '-':
  215. case '/':
  216. $s .= $ch;
  217. break;
  218. case 'Y':
  219. case 'y':
  220. $s .= '%Y';
  221. break;
  222. case 'M':
  223. $s .= '%b';
  224. break;
  225. case 'm':
  226. $s .= '%m';
  227. break;
  228. case 'D':
  229. case 'd':
  230. $s .= '%d';
  231. break;
  232. case 'Q':
  233. case 'q':
  234. $s .= "'),Quarter($col)";
  235. if ($len > $i+1) $s .= ",DATE_FORMAT($col,'";
  236. else $s .= ",('";
  237. $concat = true;
  238. break;
  239. case 'H':
  240. $s .= '%H';
  241. break;
  242. case 'h':
  243. $s .= '%I';
  244. break;
  245. case 'i':
  246. $s .= '%i';
  247. break;
  248. case 's':
  249. $s .= '%s';
  250. break;
  251. case 'a':
  252. case 'A':
  253. $s .= '%p';
  254. break;
  255. case 'w':
  256. $s .= '%w';
  257. break;
  258. case 'W':
  259. $s .= '%U';
  260. break;
  261. case 'l':
  262. $s .= '%W';
  263. break;
  264. }
  265. }
  266. $s.="')";
  267. if ($concat) $s = "CONCAT($s)";
  268. return $s;
  269. }
  270. // returns concatenated string
  271. // much easier to run "mysqld --ansi" or "mysqld --sql-mode=PIPES_AS_CONCAT" and use || operator
  272. function Concat()
  273. {
  274. $s = "";
  275. $arr = func_get_args();
  276. // suggestion by andrew005@mnogo.ru
  277. $s = implode(',',$arr);
  278. if (strlen($s) > 0) return "CONCAT($s)";
  279. else return '';
  280. }
  281. function OffsetDate($dayFraction,$date=false)
  282. {
  283. if (!$date) $date = $this->sysDate;
  284. $fraction = $dayFraction * 24 * 3600;
  285. return "from_unixtime(unix_timestamp($date)+$fraction)";
  286. }
  287. // returns true or false
  288. function _connect($argHostname, $argUsername, $argPassword, $argDatabasename)
  289. {
  290. if (!empty($this->port)) $argHostname .= ":".$this->port;
  291. if (ADODB_PHPVER >= 0x4300)
  292. $this->_connectionID = mysql_connect($argHostname,$argUsername,$argPassword,
  293. $this->forceNewConnect,$this->clientFlags);
  294. else if (ADODB_PHPVER >= 0x4200)
  295. $this->_connectionID = mysql_connect($argHostname,$argUsername,$argPassword,
  296. $this->forceNewConnect);
  297. else
  298. $this->_connectionID = mysql_connect($argHostname,$argUsername,$argPassword);
  299. if ($this->_connectionID === false) return false;
  300. if ($argDatabasename) return $this->SelectDB($argDatabasename);
  301. return true;
  302. }
  303. // returns true or false
  304. function _pconnect($argHostname, $argUsername, $argPassword, $argDatabasename)
  305. {
  306. if (!empty($this->port)) $argHostname .= ":".$this->port;
  307. if (ADODB_PHPVER >= 0x4300)
  308. $this->_connectionID = mysql_pconnect($argHostname,$argUsername,$argPassword,$this->clientFlags);
  309. else
  310. $this->_connectionID = mysql_pconnect($argHostname,$argUsername,$argPassword);
  311. if ($this->_connectionID === false) return false;
  312. if ($this->autoRollback) $this->RollbackTrans();
  313. if ($argDatabasename) return $this->SelectDB($argDatabasename);
  314. return true;
  315. }
  316. function _nconnect($argHostname, $argUsername, $argPassword, $argDatabasename)
  317. {
  318. $this->forceNewConnect = true;
  319. return $this->_connect($argHostname, $argUsername, $argPassword, $argDatabasename);
  320. }
  321. function &MetaColumns($table)
  322. {
  323. $this->_findschema($table,$schema);
  324. if ($schema) {
  325. $dbName = $this->database;
  326. $this->SelectDB($schema);
  327. }
  328. global $ADODB_FETCH_MODE;
  329. $save = $ADODB_FETCH_MODE;
  330. $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
  331. if ($this->fetchMode !== false) $savem = $this->SetFetchMode(false);
  332. $rs = $this->Execute(sprintf($this->metaColumnsSQL,$table));
  333. if ($schema) {
  334. $this->SelectDB($dbName);
  335. }
  336. if (isset($savem)) $this->SetFetchMode($savem);
  337. $ADODB_FETCH_MODE = $save;
  338. if (!is_object($rs)) {
  339. $false = false;
  340. return $false;
  341. }
  342. $retarr = array();
  343. while (!$rs->EOF){
  344. $fld = new ADOFieldObject();
  345. $fld->name = $rs->fields[0];
  346. $type = $rs->fields[1];
  347. // split type into type(length):
  348. $fld->scale = null;
  349. if (preg_match("/^(.+)\((\d+),(\d+)/", $type, $query_array)) {
  350. $fld->type = $query_array[1];
  351. $fld->max_length = is_numeric($query_array[2]) ? $query_array[2] : -1;
  352. $fld->scale = is_numeric($query_array[3]) ? $query_array[3] : -1;
  353. } elseif (preg_match("/^(.+)\((\d+)/", $type, $query_array)) {
  354. $fld->type = $query_array[1];
  355. $fld->max_length = is_numeric($query_array[2]) ? $query_array[2] : -1;
  356. } elseif (preg_match("/^(enum)\((.*)\)$/i", $type, $query_array)) {
  357. $fld->type = $query_array[1];
  358. $arr = explode(",",$query_array[2]);
  359. $fld->enums = $arr;
  360. $zlen = max(array_map("strlen",$arr)) - 2; // PHP >= 4.0.6
  361. $fld->max_length = ($zlen > 0) ? $zlen : 1;
  362. } else {
  363. $fld->type = $type;
  364. $fld->max_length = -1;
  365. }
  366. $fld->not_null = ($rs->fields[2] != 'YES');
  367. $fld->primary_key = ($rs->fields[3] == 'PRI');
  368. $fld->auto_increment = (strpos($rs->fields[5], 'auto_increment') !== false);
  369. $fld->binary = (strpos($type,'blob') !== false);
  370. $fld->unsigned = (strpos($type,'unsigned') !== false);
  371. if (!$fld->binary) {
  372. $d = $rs->fields[4];
  373. if ($d != '' && $d != 'NULL') {
  374. $fld->has_default = true;
  375. $fld->default_value = $d;
  376. } else {
  377. $fld->has_default = false;
  378. }
  379. }
  380. if ($save == ADODB_FETCH_NUM) {
  381. $retarr[] = $fld;
  382. } else {
  383. $retarr[strtoupper($fld->name)] = $fld;
  384. }
  385. $rs->MoveNext();
  386. }
  387. $rs->Close();
  388. return $retarr;
  389. }
  390. // returns true or false
  391. function SelectDB($dbName)
  392. {
  393. $this->database = $dbName;
  394. $this->databaseName = $dbName; # obsolete, retained for compat with older adodb versions
  395. if ($this->_connectionID) {
  396. return @mysql_select_db($dbName,$this->_connectionID);
  397. }
  398. else return false;
  399. }
  400. // parameters use PostgreSQL convention, not MySQL
  401. function &SelectLimit($sql,$nrows=-1,$offset=-1,$inputarr=false,$secs=0)
  402. {
  403. $offsetStr =($offset>=0) ? ((integer)$offset)."," : '';
  404. // jason judge, see http://phplens.com/lens/lensforum/msgs.php?id=9220
  405. if ($nrows < 0) $nrows = '18446744073709551615';
  406. if ($secs)
  407. $rs =& $this->CacheExecute($secs,$sql." LIMIT $offsetStr".((integer)$nrows),$inputarr);
  408. else
  409. $rs =& $this->Execute($sql." LIMIT $offsetStr".((integer)$nrows),$inputarr);
  410. return $rs;
  411. }
  412. // returns queryID or false
  413. function _query($sql,$inputarr)
  414. {
  415. //global $ADODB_COUNTRECS;
  416. //if($ADODB_COUNTRECS)
  417. return mysql_query($sql,$this->_connectionID);
  418. //else return @mysql_unbuffered_query($sql,$this->_connectionID); // requires PHP >= 4.0.6
  419. }
  420. /* Returns: the last error message from previous database operation */
  421. function ErrorMsg()
  422. {
  423. if ($this->_logsql) return $this->_errorMsg;
  424. if (empty($this->_connectionID)) $this->_errorMsg = @mysql_error();
  425. else $this->_errorMsg = @mysql_error($this->_connectionID);
  426. return $this->_errorMsg;
  427. }
  428. /* Returns: the last error number from previous database operation */
  429. function ErrorNo()
  430. {
  431. if ($this->_logsql) return $this->_errorCode;
  432. if (empty($this->_connectionID)) return @mysql_errno();
  433. else return @mysql_errno($this->_connectionID);
  434. }
  435. // returns true or false
  436. function _close()
  437. {
  438. @mysql_close($this->_connectionID);
  439. $this->_connectionID = false;
  440. }
  441. /*
  442. * Maximum size of C field
  443. */
  444. function CharMax()
  445. {
  446. return 255;
  447. }
  448. /*
  449. * Maximum size of X field
  450. */
  451. function TextMax()
  452. {
  453. return 4294967295;
  454. }
  455. // "Innox - Juan Carlos Gonzalez" <jgonzalez#innox.com.mx>
  456. function MetaForeignKeys( $table, $owner = FALSE, $upper = FALSE, $associative = FALSE )
  457. {
  458. global $ADODB_FETCH_MODE;
  459. if ($ADODB_FETCH_MODE == ADODB_FETCH_ASSOC || $this->fetchMode == ADODB_FETCH_ASSOC) $associative = true;
  460. if ( !empty($owner) ) {
  461. $table = "$owner.$table";
  462. }
  463. $a_create_table = $this->getRow(sprintf('SHOW CREATE TABLE %s', $table));
  464. if ($associative) $create_sql = $a_create_table["Create Table"];
  465. else $create_sql = $a_create_table[1];
  466. $matches = array();
  467. if (!preg_match_all("/FOREIGN KEY \(`(.*?)`\) REFERENCES `(.*?)` \(`(.*?)`\)/", $create_sql, $matches)) return false;
  468. $foreign_keys = array();
  469. $num_keys = count($matches[0]);
  470. for ( $i = 0; $i < $num_keys; $i ++ ) {
  471. $my_field = explode('`, `', $matches[1][$i]);
  472. $ref_table = $matches[2][$i];
  473. $ref_field = explode('`, `', $matches[3][$i]);
  474. if ( $upper ) {
  475. $ref_table = strtoupper($ref_table);
  476. }
  477. $foreign_keys[$ref_table] = array();
  478. $num_fields = count($my_field);
  479. for ( $j = 0; $j < $num_fields; $j ++ ) {
  480. if ( $associative ) {
  481. $foreign_keys[$ref_table][$ref_field[$j]] = $my_field[$j];
  482. } else {
  483. $foreign_keys[$ref_table][] = "{$my_field[$j]}={$ref_field[$j]}";
  484. }
  485. }
  486. }
  487. return $foreign_keys;
  488. }
  489. // Functions for managing the client encoding
  490. // Added 2004-06-20 by Kevin Jamieson (http://www.pkp.ubc.ca/)
  491. function GetCharSet()
  492. {
  493. if (function_exists('mysql_client_encoding')) {
  494. $this->charSet = @mysql_client_encoding($this->_connectionID);
  495. }
  496. if (!$this->charSet) {
  497. return false;
  498. } else {
  499. return $this->charSet;
  500. }
  501. }
  502. // SetCharSet - switch the client encoding
  503. function SetCharSet($charset_name)
  504. {
  505. if ($this->Execute('SET NAMES ?', array($charset_name))) {
  506. $this->charSet = $charset_name;
  507. return true;
  508. } else {
  509. return false;
  510. }
  511. }
  512. }
  513. /*--------------------------------------------------------------------------------------
  514. Class Name: Recordset
  515. --------------------------------------------------------------------------------------*/
  516. class ADORecordSet_mysql extends ADORecordSet{
  517. var $databaseType = "mysql";
  518. var $canSeek = true;
  519. function ADORecordSet_mysql($queryID,$mode=false)
  520. {
  521. if ($mode === false) {
  522. global $ADODB_FETCH_MODE;
  523. $mode = $ADODB_FETCH_MODE;
  524. }
  525. switch ($mode)
  526. {
  527. case ADODB_FETCH_NUM: $this->fetchMode = MYSQL_NUM; break;
  528. case ADODB_FETCH_ASSOC:$this->fetchMode = MYSQL_ASSOC; break;
  529. case ADODB_FETCH_DEFAULT:
  530. case ADODB_FETCH_BOTH:
  531. default:
  532. $this->fetchMode = MYSQL_BOTH; break;
  533. }
  534. $this->adodbFetchMode = $mode;
  535. $this->ADORecordSet($queryID);
  536. }
  537. function _initrs()
  538. {
  539. //GLOBAL $ADODB_COUNTRECS;
  540. // $this->_numOfRows = ($ADODB_COUNTRECS) ? @mysql_num_rows($this->_queryID):-1;
  541. $this->_numOfRows = @mysql_num_rows($this->_queryID);
  542. $this->_numOfFields = @mysql_num_fields($this->_queryID);
  543. }
  544. function &FetchField($fieldOffset = -1)
  545. {
  546. if ($fieldOffset != -1) {
  547. $o = @mysql_fetch_field($this->_queryID, $fieldOffset);
  548. $f = @mysql_field_flags($this->_queryID,$fieldOffset);
  549. $o->max_length = @mysql_field_len($this->_queryID,$fieldOffset); // suggested by: Jim Nicholson (jnich@att.com)
  550. //$o->max_length = -1; // mysql returns the max length less spaces -- so it is unrealiable
  551. $o->binary = (strpos($f,'binary')!== false);
  552. }
  553. else if ($fieldOffset == -1) { /* The $fieldOffset argument is not provided thus its -1 */
  554. $o = @mysql_fetch_field($this->_queryID);
  555. $o->max_length = @mysql_field_len($this->_queryID); // suggested by: Jim Nicholson (jnich@att.com)
  556. //$o->max_length = -1; // mysql returns the max length less spaces -- so it is unrealiable
  557. }
  558. return $o;
  559. }
  560. function &GetRowAssoc($upper=true)
  561. {
  562. if ($this->fetchMode == MYSQL_ASSOC && !$upper) $row = $this->fields;
  563. else $row =& ADORecordSet::GetRowAssoc($upper);
  564. return $row;
  565. }
  566. /* Use associative array to get fields array */
  567. function Fields($colname)
  568. {
  569. // added @ by "Michael William Miller" <mille562@pilot.msu.edu>
  570. if ($this->fetchMode != MYSQL_NUM) return @$this->fields[$colname];
  571. if (!$this->bind) {
  572. $this->bind = array();
  573. for ($i=0; $i < $this->_numOfFields; $i++) {
  574. $o = $this->FetchField($i);
  575. $this->bind[strtoupper($o->name)] = $i;
  576. }
  577. }
  578. return $this->fields[$this->bind[strtoupper($colname)]];
  579. }
  580. function _seek($row)
  581. {
  582. if ($this->_numOfRows == 0) return false;
  583. return @mysql_data_seek($this->_queryID,$row);
  584. }
  585. function MoveNext()
  586. {
  587. //return adodb_movenext($this);
  588. //if (defined('ADODB_EXTENSION')) return adodb_movenext($this);
  589. if (@$this->fields = mysql_fetch_array($this->_queryID,$this->fetchMode)) {
  590. $this->_currentRow += 1;
  591. return true;
  592. }
  593. if (!$this->EOF) {
  594. $this->_currentRow += 1;
  595. $this->EOF = true;
  596. }
  597. return false;
  598. }
  599. function _fetch()
  600. {
  601. $this->fields = @mysql_fetch_array($this->_queryID,$this->fetchMode);
  602. return is_array($this->fields);
  603. }
  604. function _close() {
  605. @mysql_free_result($this->_queryID);
  606. $this->_queryID = false;
  607. }
  608. function MetaType($t,$len=-1,$fieldobj=false)
  609. {
  610. if (is_object($t)) {
  611. $fieldobj = $t;
  612. $t = $fieldobj->type;
  613. $len = $fieldobj->max_length;
  614. }
  615. $len = -1; // mysql max_length is not accurate
  616. switch (strtoupper($t)) {
  617. case 'STRING':
  618. case 'CHAR':
  619. case 'VARCHAR':
  620. case 'TINYBLOB':
  621. case 'TINYTEXT':
  622. case 'ENUM':
  623. case 'SET':
  624. if ($len <= $this->blobSize) return 'C';
  625. case 'TEXT':
  626. case 'LONGTEXT':
  627. case 'MEDIUMTEXT':
  628. return 'X';
  629. // php_mysql extension always returns 'blob' even if 'text'
  630. // so we have to check whether binary...
  631. case 'IMAGE':
  632. case 'LONGBLOB':
  633. case 'BLOB':
  634. case 'MEDIUMBLOB':
  635. return !empty($fieldobj->binary) ? 'B' : 'X';
  636. case 'YEAR':
  637. case 'DATE': return 'D';
  638. case 'TIME':
  639. case 'DATETIME':
  640. case 'TIMESTAMP': return 'T';
  641. case 'INT':
  642. case 'INTEGER':
  643. case 'BIGINT':
  644. case 'TINYINT':
  645. case 'MEDIUMINT':
  646. case 'SMALLINT':
  647. if (!empty($fieldobj->primary_key)) return 'R';
  648. else return 'I';
  649. default: return 'N';
  650. }
  651. }
  652. }
  653. class ADORecordSet_ext_mysql extends ADORecordSet_mysql {
  654. function ADORecordSet_ext_mysql($queryID,$mode=false)
  655. {
  656. if ($mode === false) {
  657. global $ADODB_FETCH_MODE;
  658. $mode = $ADODB_FETCH_MODE;
  659. }
  660. switch ($mode)
  661. {
  662. case ADODB_FETCH_NUM: $this->fetchMode = MYSQL_NUM; break;
  663. case ADODB_FETCH_ASSOC:$this->fetchMode = MYSQL_ASSOC; break;
  664. case ADODB_FETCH_DEFAULT:
  665. case ADODB_FETCH_BOTH:
  666. default:
  667. $this->fetchMode = MYSQL_BOTH; break;
  668. }
  669. $this->adodbFetchMode = $mode;
  670. $this->ADORecordSet($queryID);
  671. }
  672. function MoveNext()
  673. {
  674. return @adodb_movenext($this);
  675. }
  676. }
  677. }
  678. ?>