PageRenderTime 58ms CodeModel.GetById 25ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://github.com/Fusion/lenses
PHP | 789 lines | 612 code | 114 blank | 63 comment | 127 complexity | 84d533a33729477d7e21ed019b79699f MD5 | raw file
Possible License(s): BSD-3-Clause
  1. <?php
  2. /*
  3. V5.04a 25 Mar 2008 (c) 2000-2008 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 (is_null($s)) return 'NULL';
  110. if (!$magic_quotes) {
  111. if (ADODB_PHPVER >= 0x4300) {
  112. if (is_resource($this->_connectionID))
  113. return "'".mysql_real_escape_string($s,$this->_connectionID)."'";
  114. }
  115. if ($this->replaceQuote[0] == '\\'){
  116. $s = adodb_str_replace(array('\\',"\0"),array('\\\\',"\\\0"),$s);
  117. }
  118. return "'".str_replace("'",$this->replaceQuote,$s)."'";
  119. }
  120. // undo magic quotes for "
  121. $s = str_replace('\\"','"',$s);
  122. return "'$s'";
  123. }
  124. function _insertid()
  125. {
  126. return ADOConnection::GetOne('SELECT LAST_INSERT_ID()');
  127. //return mysql_insert_id($this->_connectionID);
  128. }
  129. function GetOne($sql,$inputarr=false)
  130. {
  131. if ($this->compat323 == false && strncasecmp($sql,'sele',4) == 0) {
  132. $rs = $this->SelectLimit($sql,1,-1,$inputarr);
  133. if ($rs) {
  134. $rs->Close();
  135. if ($rs->EOF) return false;
  136. return reset($rs->fields);
  137. }
  138. } else {
  139. return ADOConnection::GetOne($sql,$inputarr);
  140. }
  141. return false;
  142. }
  143. function BeginTrans()
  144. {
  145. if ($this->debug) ADOConnection::outp("Transactions not supported in 'mysql' driver. Use 'mysqlt' or 'mysqli' driver");
  146. }
  147. function _affectedrows()
  148. {
  149. return mysql_affected_rows($this->_connectionID);
  150. }
  151. // See http://www.mysql.com/doc/M/i/Miscellaneous_functions.html
  152. // Reference on Last_Insert_ID on the recommended way to simulate sequences
  153. var $_genIDSQL = "update %s set id=LAST_INSERT_ID(id+1);";
  154. var $_genSeqSQL = "create table %s (id int not null)";
  155. var $_genSeqCountSQL = "select count(*) from %s";
  156. var $_genSeq2SQL = "insert into %s values (%s)";
  157. var $_dropSeqSQL = "drop table %s";
  158. function CreateSequence($seqname='adodbseq',$startID=1)
  159. {
  160. if (empty($this->_genSeqSQL)) return false;
  161. $u = strtoupper($seqname);
  162. $ok = $this->Execute(sprintf($this->_genSeqSQL,$seqname));
  163. if (!$ok) return false;
  164. return $this->Execute(sprintf($this->_genSeq2SQL,$seqname,$startID-1));
  165. }
  166. function GenID($seqname='adodbseq',$startID=1)
  167. {
  168. // post-nuke sets hasGenID to false
  169. if (!$this->hasGenID) return false;
  170. $savelog = $this->_logsql;
  171. $this->_logsql = false;
  172. $getnext = sprintf($this->_genIDSQL,$seqname);
  173. $holdtransOK = $this->_transOK; // save the current status
  174. $rs = @$this->Execute($getnext);
  175. if (!$rs) {
  176. if ($holdtransOK) $this->_transOK = true; //if the status was ok before reset
  177. $u = strtoupper($seqname);
  178. $this->Execute(sprintf($this->_genSeqSQL,$seqname));
  179. $cnt = $this->GetOne(sprintf($this->_genSeqCountSQL,$seqname));
  180. if (!$cnt) $this->Execute(sprintf($this->_genSeq2SQL,$seqname,$startID-1));
  181. $rs = $this->Execute($getnext);
  182. }
  183. if ($rs) {
  184. $this->genID = mysql_insert_id($this->_connectionID);
  185. $rs->Close();
  186. } else
  187. $this->genID = 0;
  188. $this->_logsql = $savelog;
  189. return $this->genID;
  190. }
  191. function MetaDatabases()
  192. {
  193. $qid = mysql_list_dbs($this->_connectionID);
  194. $arr = array();
  195. $i = 0;
  196. $max = mysql_num_rows($qid);
  197. while ($i < $max) {
  198. $db = mysql_tablename($qid,$i);
  199. if ($db != 'mysql') $arr[] = $db;
  200. $i += 1;
  201. }
  202. return $arr;
  203. }
  204. // Format date column in sql string given an input format that understands Y M D
  205. function SQLDate($fmt, $col=false)
  206. {
  207. if (!$col) $col = $this->sysTimeStamp;
  208. $s = 'DATE_FORMAT('.$col.",'";
  209. $concat = false;
  210. $len = strlen($fmt);
  211. for ($i=0; $i < $len; $i++) {
  212. $ch = $fmt[$i];
  213. switch($ch) {
  214. default:
  215. if ($ch == '\\') {
  216. $i++;
  217. $ch = substr($fmt,$i,1);
  218. }
  219. /** FALL THROUGH */
  220. case '-':
  221. case '/':
  222. $s .= $ch;
  223. break;
  224. case 'Y':
  225. case 'y':
  226. $s .= '%Y';
  227. break;
  228. case 'M':
  229. $s .= '%b';
  230. break;
  231. case 'm':
  232. $s .= '%m';
  233. break;
  234. case 'D':
  235. case 'd':
  236. $s .= '%d';
  237. break;
  238. case 'Q':
  239. case 'q':
  240. $s .= "'),Quarter($col)";
  241. if ($len > $i+1) $s .= ",DATE_FORMAT($col,'";
  242. else $s .= ",('";
  243. $concat = true;
  244. break;
  245. case 'H':
  246. $s .= '%H';
  247. break;
  248. case 'h':
  249. $s .= '%I';
  250. break;
  251. case 'i':
  252. $s .= '%i';
  253. break;
  254. case 's':
  255. $s .= '%s';
  256. break;
  257. case 'a':
  258. case 'A':
  259. $s .= '%p';
  260. break;
  261. case 'w':
  262. $s .= '%w';
  263. break;
  264. case 'W':
  265. $s .= '%U';
  266. break;
  267. case 'l':
  268. $s .= '%W';
  269. break;
  270. }
  271. }
  272. $s.="')";
  273. if ($concat) $s = "CONCAT($s)";
  274. return $s;
  275. }
  276. // returns concatenated string
  277. // much easier to run "mysqld --ansi" or "mysqld --sql-mode=PIPES_AS_CONCAT" and use || operator
  278. function Concat()
  279. {
  280. $s = "";
  281. $arr = func_get_args();
  282. // suggestion by andrew005@mnogo.ru
  283. $s = implode(',',$arr);
  284. if (strlen($s) > 0) return "CONCAT($s)";
  285. else return '';
  286. }
  287. function OffsetDate($dayFraction,$date=false)
  288. {
  289. if (!$date) $date = $this->sysDate;
  290. $fraction = $dayFraction * 24 * 3600;
  291. return $date . ' + INTERVAL ' . $fraction.' SECOND';
  292. // return "from_unixtime(unix_timestamp($date)+$fraction)";
  293. }
  294. // returns true or false
  295. function _connect($argHostname, $argUsername, $argPassword, $argDatabasename)
  296. {
  297. if (!empty($this->port)) $argHostname .= ":".$this->port;
  298. if (ADODB_PHPVER >= 0x4300)
  299. $this->_connectionID = mysql_connect($argHostname,$argUsername,$argPassword,
  300. $this->forceNewConnect,$this->clientFlags);
  301. else if (ADODB_PHPVER >= 0x4200)
  302. $this->_connectionID = mysql_connect($argHostname,$argUsername,$argPassword,
  303. $this->forceNewConnect);
  304. else
  305. $this->_connectionID = mysql_connect($argHostname,$argUsername,$argPassword);
  306. if ($this->_connectionID === false) return false;
  307. if ($argDatabasename) return $this->SelectDB($argDatabasename);
  308. return true;
  309. }
  310. // returns true or false
  311. function _pconnect($argHostname, $argUsername, $argPassword, $argDatabasename)
  312. {
  313. if (!empty($this->port)) $argHostname .= ":".$this->port;
  314. if (ADODB_PHPVER >= 0x4300)
  315. $this->_connectionID = mysql_pconnect($argHostname,$argUsername,$argPassword,$this->clientFlags);
  316. else
  317. $this->_connectionID = mysql_pconnect($argHostname,$argUsername,$argPassword);
  318. if ($this->_connectionID === false) return false;
  319. if ($this->autoRollback) $this->RollbackTrans();
  320. if ($argDatabasename) return $this->SelectDB($argDatabasename);
  321. return true;
  322. }
  323. function _nconnect($argHostname, $argUsername, $argPassword, $argDatabasename)
  324. {
  325. $this->forceNewConnect = true;
  326. return $this->_connect($argHostname, $argUsername, $argPassword, $argDatabasename);
  327. }
  328. function MetaColumns($table)
  329. {
  330. $this->_findschema($table,$schema);
  331. if ($schema) {
  332. $dbName = $this->database;
  333. $this->SelectDB($schema);
  334. }
  335. global $ADODB_FETCH_MODE;
  336. $save = $ADODB_FETCH_MODE;
  337. $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
  338. if ($this->fetchMode !== false) $savem = $this->SetFetchMode(false);
  339. $rs = $this->Execute(sprintf($this->metaColumnsSQL,$table));
  340. if ($schema) {
  341. $this->SelectDB($dbName);
  342. }
  343. if (isset($savem)) $this->SetFetchMode($savem);
  344. $ADODB_FETCH_MODE = $save;
  345. if (!is_object($rs)) {
  346. $false = false;
  347. return $false;
  348. }
  349. $retarr = array();
  350. while (!$rs->EOF){
  351. $fld = new ADOFieldObject();
  352. $fld->name = $rs->fields[0];
  353. $type = $rs->fields[1];
  354. // split type into type(length):
  355. $fld->scale = null;
  356. if (preg_match("/^(.+)\((\d+),(\d+)/", $type, $query_array)) {
  357. $fld->type = $query_array[1];
  358. $fld->max_length = is_numeric($query_array[2]) ? $query_array[2] : -1;
  359. $fld->scale = is_numeric($query_array[3]) ? $query_array[3] : -1;
  360. } elseif (preg_match("/^(.+)\((\d+)/", $type, $query_array)) {
  361. $fld->type = $query_array[1];
  362. $fld->max_length = is_numeric($query_array[2]) ? $query_array[2] : -1;
  363. } elseif (preg_match("/^(enum)\((.*)\)$/i", $type, $query_array)) {
  364. $fld->type = $query_array[1];
  365. $arr = explode(",",$query_array[2]);
  366. $fld->enums = $arr;
  367. $zlen = max(array_map("strlen",$arr)) - 2; // PHP >= 4.0.6
  368. $fld->max_length = ($zlen > 0) ? $zlen : 1;
  369. } else {
  370. $fld->type = $type;
  371. $fld->max_length = -1;
  372. }
  373. $fld->not_null = ($rs->fields[2] != 'YES');
  374. $fld->primary_key = ($rs->fields[3] == 'PRI');
  375. $fld->auto_increment = (strpos($rs->fields[5], 'auto_increment') !== false);
  376. $fld->binary = (strpos($type,'blob') !== false);
  377. $fld->unsigned = (strpos($type,'unsigned') !== false);
  378. $fld->zerofill = (strpos($type,'zerofill') !== false);
  379. if (!$fld->binary) {
  380. $d = $rs->fields[4];
  381. if ($d != '' && $d != 'NULL') {
  382. $fld->has_default = true;
  383. $fld->default_value = $d;
  384. } else {
  385. $fld->has_default = false;
  386. }
  387. }
  388. if ($save == ADODB_FETCH_NUM) {
  389. $retarr[] = $fld;
  390. } else {
  391. $retarr[strtoupper($fld->name)] = $fld;
  392. }
  393. $rs->MoveNext();
  394. }
  395. $rs->Close();
  396. return $retarr;
  397. }
  398. // returns true or false
  399. function SelectDB($dbName)
  400. {
  401. $this->database = $dbName;
  402. $this->databaseName = $dbName; # obsolete, retained for compat with older adodb versions
  403. if ($this->_connectionID) {
  404. return @mysql_select_db($dbName,$this->_connectionID);
  405. }
  406. else return false;
  407. }
  408. // parameters use PostgreSQL convention, not MySQL
  409. function SelectLimit($sql,$nrows=-1,$offset=-1,$inputarr=false,$secs=0)
  410. {
  411. $offsetStr =($offset>=0) ? ((integer)$offset)."," : '';
  412. // jason judge, see http://phplens.com/lens/lensforum/msgs.php?id=9220
  413. if ($nrows < 0) $nrows = '18446744073709551615';
  414. if ($secs)
  415. $rs = $this->CacheExecute($secs,$sql." LIMIT $offsetStr".((integer)$nrows),$inputarr);
  416. else
  417. $rs = $this->Execute($sql." LIMIT $offsetStr".((integer)$nrows),$inputarr);
  418. return $rs;
  419. }
  420. // returns queryID or false
  421. function _query($sql,$inputarr)
  422. {
  423. //global $ADODB_COUNTRECS;
  424. //if($ADODB_COUNTRECS)
  425. return mysql_query($sql,$this->_connectionID);
  426. //else return @mysql_unbuffered_query($sql,$this->_connectionID); // requires PHP >= 4.0.6
  427. }
  428. /* Returns: the last error message from previous database operation */
  429. function ErrorMsg()
  430. {
  431. if ($this->_logsql) return $this->_errorMsg;
  432. if (empty($this->_connectionID)) $this->_errorMsg = @mysql_error();
  433. else $this->_errorMsg = @mysql_error($this->_connectionID);
  434. return $this->_errorMsg;
  435. }
  436. /* Returns: the last error number from previous database operation */
  437. function ErrorNo()
  438. {
  439. if ($this->_logsql) return $this->_errorCode;
  440. if (empty($this->_connectionID)) return @mysql_errno();
  441. else return @mysql_errno($this->_connectionID);
  442. }
  443. // returns true or false
  444. function _close()
  445. {
  446. @mysql_close($this->_connectionID);
  447. $this->_connectionID = false;
  448. }
  449. /*
  450. * Maximum size of C field
  451. */
  452. function CharMax()
  453. {
  454. return 255;
  455. }
  456. /*
  457. * Maximum size of X field
  458. */
  459. function TextMax()
  460. {
  461. return 4294967295;
  462. }
  463. // "Innox - Juan Carlos Gonzalez" <jgonzalez#innox.com.mx>
  464. function MetaForeignKeys( $table, $owner = FALSE, $upper = FALSE, $associative = FALSE )
  465. {
  466. global $ADODB_FETCH_MODE;
  467. if ($ADODB_FETCH_MODE == ADODB_FETCH_ASSOC || $this->fetchMode == ADODB_FETCH_ASSOC) $associative = true;
  468. if ( !empty($owner) ) {
  469. $table = "$owner.$table";
  470. }
  471. $a_create_table = $this->getRow(sprintf('SHOW CREATE TABLE %s', $table));
  472. if ($associative) $create_sql = $a_create_table["Create Table"];
  473. else $create_sql = $a_create_table[1];
  474. $matches = array();
  475. if (!preg_match_all("/FOREIGN KEY \(`(.*?)`\) REFERENCES `(.*?)` \(`(.*?)`\)/", $create_sql, $matches)) return false;
  476. $foreign_keys = array();
  477. $num_keys = count($matches[0]);
  478. for ( $i = 0; $i < $num_keys; $i ++ ) {
  479. $my_field = explode('`, `', $matches[1][$i]);
  480. $ref_table = $matches[2][$i];
  481. $ref_field = explode('`, `', $matches[3][$i]);
  482. if ( $upper ) {
  483. $ref_table = strtoupper($ref_table);
  484. }
  485. $foreign_keys[$ref_table] = array();
  486. $num_fields = count($my_field);
  487. for ( $j = 0; $j < $num_fields; $j ++ ) {
  488. if ( $associative ) {
  489. $foreign_keys[$ref_table][$ref_field[$j]] = $my_field[$j];
  490. } else {
  491. $foreign_keys[$ref_table][] = "{$my_field[$j]}={$ref_field[$j]}";
  492. }
  493. }
  494. }
  495. return $foreign_keys;
  496. }
  497. }
  498. /*--------------------------------------------------------------------------------------
  499. Class Name: Recordset
  500. --------------------------------------------------------------------------------------*/
  501. class ADORecordSet_mysql extends ADORecordSet{
  502. var $databaseType = "mysql";
  503. var $canSeek = true;
  504. function ADORecordSet_mysql($queryID,$mode=false)
  505. {
  506. if ($mode === false) {
  507. global $ADODB_FETCH_MODE;
  508. $mode = $ADODB_FETCH_MODE;
  509. }
  510. switch ($mode)
  511. {
  512. case ADODB_FETCH_NUM: $this->fetchMode = MYSQL_NUM; break;
  513. case ADODB_FETCH_ASSOC:$this->fetchMode = MYSQL_ASSOC; break;
  514. case ADODB_FETCH_DEFAULT:
  515. case ADODB_FETCH_BOTH:
  516. default:
  517. $this->fetchMode = MYSQL_BOTH; break;
  518. }
  519. $this->adodbFetchMode = $mode;
  520. $this->ADORecordSet($queryID);
  521. }
  522. function _initrs()
  523. {
  524. //GLOBAL $ADODB_COUNTRECS;
  525. // $this->_numOfRows = ($ADODB_COUNTRECS) ? @mysql_num_rows($this->_queryID):-1;
  526. $this->_numOfRows = @mysql_num_rows($this->_queryID);
  527. $this->_numOfFields = @mysql_num_fields($this->_queryID);
  528. }
  529. function FetchField($fieldOffset = -1)
  530. {
  531. if ($fieldOffset != -1) {
  532. $o = @mysql_fetch_field($this->_queryID, $fieldOffset);
  533. $f = @mysql_field_flags($this->_queryID,$fieldOffset);
  534. if ($o) $o->max_length = @mysql_field_len($this->_queryID,$fieldOffset); // suggested by: Jim Nicholson (jnich#att.com)
  535. //$o->max_length = -1; // mysql returns the max length less spaces -- so it is unrealiable
  536. if ($o) $o->binary = (strpos($f,'binary')!== false);
  537. }
  538. else if ($fieldOffset == -1) { /* The $fieldOffset argument is not provided thus its -1 */
  539. $o = @mysql_fetch_field($this->_queryID);
  540. if ($o) $o->max_length = @mysql_field_len($this->_queryID); // suggested by: Jim Nicholson (jnich#att.com)
  541. //$o->max_length = -1; // mysql returns the max length less spaces -- so it is unrealiable
  542. }
  543. return $o;
  544. }
  545. function GetRowAssoc($upper=true)
  546. {
  547. if ($this->fetchMode == MYSQL_ASSOC && !$upper) $row = $this->fields;
  548. else $row = ADORecordSet::GetRowAssoc($upper);
  549. return $row;
  550. }
  551. /* Use associative array to get fields array */
  552. function Fields($colname)
  553. {
  554. // added @ by "Michael William Miller" <mille562@pilot.msu.edu>
  555. if ($this->fetchMode != MYSQL_NUM) return @$this->fields[$colname];
  556. if (!$this->bind) {
  557. $this->bind = array();
  558. for ($i=0; $i < $this->_numOfFields; $i++) {
  559. $o = $this->FetchField($i);
  560. $this->bind[strtoupper($o->name)] = $i;
  561. }
  562. }
  563. return $this->fields[$this->bind[strtoupper($colname)]];
  564. }
  565. function _seek($row)
  566. {
  567. if ($this->_numOfRows == 0) return false;
  568. return @mysql_data_seek($this->_queryID,$row);
  569. }
  570. function MoveNext()
  571. {
  572. //return adodb_movenext($this);
  573. //if (defined('ADODB_EXTENSION')) return adodb_movenext($this);
  574. if (@$this->fields = mysql_fetch_array($this->_queryID,$this->fetchMode)) {
  575. $this->_currentRow += 1;
  576. return true;
  577. }
  578. if (!$this->EOF) {
  579. $this->_currentRow += 1;
  580. $this->EOF = true;
  581. }
  582. return false;
  583. }
  584. function _fetch()
  585. {
  586. $this->fields = @mysql_fetch_array($this->_queryID,$this->fetchMode);
  587. return is_array($this->fields);
  588. }
  589. function _close() {
  590. @mysql_free_result($this->_queryID);
  591. $this->_queryID = false;
  592. }
  593. function MetaType($t,$len=-1,$fieldobj=false)
  594. {
  595. if (is_object($t)) {
  596. $fieldobj = $t;
  597. $t = $fieldobj->type;
  598. $len = $fieldobj->max_length;
  599. }
  600. $len = -1; // mysql max_length is not accurate
  601. switch (strtoupper($t)) {
  602. case 'STRING':
  603. case 'CHAR':
  604. case 'VARCHAR':
  605. case 'TINYBLOB':
  606. case 'TINYTEXT':
  607. case 'ENUM':
  608. case 'SET':
  609. if ($len <= $this->blobSize) return 'C';
  610. case 'TEXT':
  611. case 'LONGTEXT':
  612. case 'MEDIUMTEXT':
  613. return 'X';
  614. // php_mysql extension always returns 'blob' even if 'text'
  615. // so we have to check whether binary...
  616. case 'IMAGE':
  617. case 'LONGBLOB':
  618. case 'BLOB':
  619. case 'MEDIUMBLOB':
  620. return !empty($fieldobj->binary) ? 'B' : 'X';
  621. case 'YEAR':
  622. case 'DATE': return 'D';
  623. case 'TIME':
  624. case 'DATETIME':
  625. case 'TIMESTAMP': return 'T';
  626. case 'INT':
  627. case 'INTEGER':
  628. case 'BIGINT':
  629. case 'TINYINT':
  630. case 'MEDIUMINT':
  631. case 'SMALLINT':
  632. if (!empty($fieldobj->primary_key)) return 'R';
  633. else return 'I';
  634. default: return 'N';
  635. }
  636. }
  637. }
  638. class ADORecordSet_ext_mysql extends ADORecordSet_mysql {
  639. function ADORecordSet_ext_mysql($queryID,$mode=false)
  640. {
  641. if ($mode === false) {
  642. global $ADODB_FETCH_MODE;
  643. $mode = $ADODB_FETCH_MODE;
  644. }
  645. switch ($mode)
  646. {
  647. case ADODB_FETCH_NUM: $this->fetchMode = MYSQL_NUM; break;
  648. case ADODB_FETCH_ASSOC:$this->fetchMode = MYSQL_ASSOC; break;
  649. case ADODB_FETCH_DEFAULT:
  650. case ADODB_FETCH_BOTH:
  651. default:
  652. $this->fetchMode = MYSQL_BOTH; break;
  653. }
  654. $this->adodbFetchMode = $mode;
  655. $this->ADORecordSet($queryID);
  656. }
  657. function MoveNext()
  658. {
  659. return @adodb_movenext($this);
  660. }
  661. }
  662. }
  663. ?>