PageRenderTime 53ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/libraries/adodb.493a/drivers/adodb-odbc.inc.php

https://github.com/infused/retrospect-gds
PHP | 738 lines | 506 code | 109 blank | 123 comment | 143 complexity | 722187012ca26ff01de6f237cc98e70b MD5 | raw file
Possible License(s): AGPL-1.0, LGPL-2.1
  1. <?php
  2. /*
  3. V4.93 10 Oct 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 4 for best viewing.
  8. Latest version is available at http://adodb.sourceforge.net
  9. Requires ODBC. Works on Windows and Unix.
  10. */
  11. // security - hide paths
  12. if (!defined('ADODB_DIR')) die();
  13. define("_ADODB_ODBC_LAYER", 2 );
  14. /*--------------------------------------------------------------------------------------
  15. --------------------------------------------------------------------------------------*/
  16. class ADODB_odbc extends ADOConnection {
  17. var $databaseType = "odbc";
  18. var $fmtDate = "'Y-m-d'";
  19. var $fmtTimeStamp = "'Y-m-d, h:i:sA'";
  20. var $replaceQuote = "''"; // string to use to replace quotes
  21. var $dataProvider = "odbc";
  22. var $hasAffectedRows = true;
  23. var $binmode = ODBC_BINMODE_RETURN;
  24. var $useFetchArray = false; // setting this to true will make array elements in FETCH_ASSOC mode case-sensitive
  25. // breaking backward-compat
  26. //var $longreadlen = 8000; // default number of chars to return for a Blob/Long field
  27. var $_bindInputArray = false;
  28. var $curmode = SQL_CUR_USE_DRIVER; // See sqlext.h, SQL_CUR_DEFAULT == SQL_CUR_USE_DRIVER == 2L
  29. var $_genSeqSQL = "create table %s (id integer)";
  30. var $_autocommit = true;
  31. var $_haserrorfunctions = true;
  32. var $_has_stupid_odbc_fetch_api_change = true;
  33. var $_lastAffectedRows = 0;
  34. var $uCaseTables = true; // for meta* functions, uppercase table names
  35. function ADODB_odbc()
  36. {
  37. $this->_haserrorfunctions = ADODB_PHPVER >= 0x4050;
  38. $this->_has_stupid_odbc_fetch_api_change = ADODB_PHPVER >= 0x4200;
  39. }
  40. // returns true or false
  41. function _connect($argDSN, $argUsername, $argPassword, $argDatabasename)
  42. {
  43. global $php_errormsg;
  44. if (!function_exists('odbc_connect')) return null;
  45. if ($this->debug && $argDatabasename && $this->databaseType != 'vfp') {
  46. ADOConnection::outp("For odbc Connect(), $argDatabasename is not used. Place dsn in 1st parameter.");
  47. }
  48. if (isset($php_errormsg)) $php_errormsg = '';
  49. if ($this->curmode === false) $this->_connectionID = odbc_connect($argDSN,$argUsername,$argPassword);
  50. else $this->_connectionID = odbc_connect($argDSN,$argUsername,$argPassword,$this->curmode);
  51. $this->_errorMsg = isset($php_errormsg) ? $php_errormsg : '';
  52. if (isset($this->connectStmt)) $this->Execute($this->connectStmt);
  53. return $this->_connectionID != false;
  54. }
  55. // returns true or false
  56. function _pconnect($argDSN, $argUsername, $argPassword, $argDatabasename)
  57. {
  58. global $php_errormsg;
  59. if (!function_exists('odbc_connect')) return null;
  60. if (isset($php_errormsg)) $php_errormsg = '';
  61. $this->_errorMsg = isset($php_errormsg) ? $php_errormsg : '';
  62. if ($this->debug && $argDatabasename) {
  63. ADOConnection::outp("For odbc PConnect(), $argDatabasename is not used. Place dsn in 1st parameter.");
  64. }
  65. // print "dsn=$argDSN u=$argUsername p=$argPassword<br>"; flush();
  66. if ($this->curmode === false) $this->_connectionID = odbc_connect($argDSN,$argUsername,$argPassword);
  67. else $this->_connectionID = odbc_pconnect($argDSN,$argUsername,$argPassword,$this->curmode);
  68. $this->_errorMsg = isset($php_errormsg) ? $php_errormsg : '';
  69. if ($this->_connectionID && $this->autoRollback) @odbc_rollback($this->_connectionID);
  70. if (isset($this->connectStmt)) $this->Execute($this->connectStmt);
  71. return $this->_connectionID != false;
  72. }
  73. function ServerInfo()
  74. {
  75. if (!empty($this->host) && ADODB_PHPVER >= 0x4300) {
  76. $dsn = strtoupper($this->host);
  77. $first = true;
  78. $found = false;
  79. if (!function_exists('odbc_data_source')) return false;
  80. while(true) {
  81. $rez = @odbc_data_source($this->_connectionID,
  82. $first ? SQL_FETCH_FIRST : SQL_FETCH_NEXT);
  83. $first = false;
  84. if (!is_array($rez)) break;
  85. if (strtoupper($rez['server']) == $dsn) {
  86. $found = true;
  87. break;
  88. }
  89. }
  90. if (!$found) return ADOConnection::ServerInfo();
  91. if (!isset($rez['version'])) $rez['version'] = '';
  92. return $rez;
  93. } else {
  94. return ADOConnection::ServerInfo();
  95. }
  96. }
  97. function CreateSequence($seqname='adodbseq',$start=1)
  98. {
  99. if (empty($this->_genSeqSQL)) return false;
  100. $ok = $this->Execute(sprintf($this->_genSeqSQL,$seqname));
  101. if (!$ok) return false;
  102. $start -= 1;
  103. return $this->Execute("insert into $seqname values($start)");
  104. }
  105. var $_dropSeqSQL = 'drop table %s';
  106. function DropSequence($seqname)
  107. {
  108. if (empty($this->_dropSeqSQL)) return false;
  109. return $this->Execute(sprintf($this->_dropSeqSQL,$seqname));
  110. }
  111. /*
  112. This algorithm is not very efficient, but works even if table locking
  113. is not available.
  114. Will return false if unable to generate an ID after $MAXLOOPS attempts.
  115. */
  116. function GenID($seq='adodbseq',$start=1)
  117. {
  118. // if you have to modify the parameter below, your database is overloaded,
  119. // or you need to implement generation of id's yourself!
  120. $MAXLOOPS = 100;
  121. //$this->debug=1;
  122. while (--$MAXLOOPS>=0) {
  123. $num = $this->GetOne("select id from $seq");
  124. if ($num === false) {
  125. $this->Execute(sprintf($this->_genSeqSQL ,$seq));
  126. $start -= 1;
  127. $num = '0';
  128. $ok = $this->Execute("insert into $seq values($start)");
  129. if (!$ok) return false;
  130. }
  131. $this->Execute("update $seq set id=id+1 where id=$num");
  132. if ($this->affected_rows() > 0) {
  133. $num += 1;
  134. $this->genID = $num;
  135. return $num;
  136. }
  137. }
  138. if ($fn = $this->raiseErrorFn) {
  139. $fn($this->databaseType,'GENID',-32000,"Unable to generate unique id after $MAXLOOPS attempts",$seq,$num);
  140. }
  141. return false;
  142. }
  143. function ErrorMsg()
  144. {
  145. if ($this->_haserrorfunctions) {
  146. if ($this->_errorMsg !== false) return $this->_errorMsg;
  147. if (empty($this->_connectionID)) return @odbc_errormsg();
  148. return @odbc_errormsg($this->_connectionID);
  149. } else return ADOConnection::ErrorMsg();
  150. }
  151. function ErrorNo()
  152. {
  153. if ($this->_haserrorfunctions) {
  154. if ($this->_errorCode !== false) {
  155. // bug in 4.0.6, error number can be corrupted string (should be 6 digits)
  156. return (strlen($this->_errorCode)<=2) ? 0 : $this->_errorCode;
  157. }
  158. if (empty($this->_connectionID)) $e = @odbc_error();
  159. else $e = @odbc_error($this->_connectionID);
  160. // bug in 4.0.6, error number can be corrupted string (should be 6 digits)
  161. // so we check and patch
  162. if (strlen($e)<=2) return 0;
  163. return $e;
  164. } else return ADOConnection::ErrorNo();
  165. }
  166. function BeginTrans()
  167. {
  168. if (!$this->hasTransactions) return false;
  169. if ($this->transOff) return true;
  170. $this->transCnt += 1;
  171. $this->_autocommit = false;
  172. return odbc_autocommit($this->_connectionID,false);
  173. }
  174. function CommitTrans($ok=true)
  175. {
  176. if ($this->transOff) return true;
  177. if (!$ok) return $this->RollbackTrans();
  178. if ($this->transCnt) $this->transCnt -= 1;
  179. $this->_autocommit = true;
  180. $ret = odbc_commit($this->_connectionID);
  181. odbc_autocommit($this->_connectionID,true);
  182. return $ret;
  183. }
  184. function RollbackTrans()
  185. {
  186. if ($this->transOff) return true;
  187. if ($this->transCnt) $this->transCnt -= 1;
  188. $this->_autocommit = true;
  189. $ret = odbc_rollback($this->_connectionID);
  190. odbc_autocommit($this->_connectionID,true);
  191. return $ret;
  192. }
  193. function MetaPrimaryKeys($table)
  194. {
  195. global $ADODB_FETCH_MODE;
  196. if ($this->uCaseTables) $table = strtoupper($table);
  197. $schema = '';
  198. $this->_findschema($table,$schema);
  199. $savem = $ADODB_FETCH_MODE;
  200. $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
  201. $qid = @odbc_primarykeys($this->_connectionID,'',$schema,$table);
  202. if (!$qid) {
  203. $ADODB_FETCH_MODE = $savem;
  204. return false;
  205. }
  206. $rs = new ADORecordSet_odbc($qid);
  207. $ADODB_FETCH_MODE = $savem;
  208. if (!$rs) return false;
  209. $rs->_has_stupid_odbc_fetch_api_change = $this->_has_stupid_odbc_fetch_api_change;
  210. $arr =& $rs->GetArray();
  211. $rs->Close();
  212. //print_r($arr);
  213. $arr2 = array();
  214. for ($i=0; $i < sizeof($arr); $i++) {
  215. if ($arr[$i][3]) $arr2[] = $arr[$i][3];
  216. }
  217. return $arr2;
  218. }
  219. function &MetaTables($ttype=false)
  220. {
  221. global $ADODB_FETCH_MODE;
  222. $savem = $ADODB_FETCH_MODE;
  223. $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
  224. $qid = odbc_tables($this->_connectionID);
  225. $rs = new ADORecordSet_odbc($qid);
  226. $ADODB_FETCH_MODE = $savem;
  227. if (!$rs) {
  228. $false = false;
  229. return $false;
  230. }
  231. $rs->_has_stupid_odbc_fetch_api_change = $this->_has_stupid_odbc_fetch_api_change;
  232. $arr =& $rs->GetArray();
  233. //print_r($arr);
  234. $rs->Close();
  235. $arr2 = array();
  236. if ($ttype) {
  237. $isview = strncmp($ttype,'V',1) === 0;
  238. }
  239. for ($i=0; $i < sizeof($arr); $i++) {
  240. if (!$arr[$i][2]) continue;
  241. $type = $arr[$i][3];
  242. if ($ttype) {
  243. if ($isview) {
  244. if (strncmp($type,'V',1) === 0) $arr2[] = $arr[$i][2];
  245. } else if (strncmp($type,'SYS',3) !== 0) $arr2[] = $arr[$i][2];
  246. } else if (strncmp($type,'SYS',3) !== 0) $arr2[] = $arr[$i][2];
  247. }
  248. return $arr2;
  249. }
  250. /*
  251. See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odbc/htm/odbcdatetime_data_type_changes.asp
  252. / SQL data type codes /
  253. #define SQL_UNKNOWN_TYPE 0
  254. #define SQL_CHAR 1
  255. #define SQL_NUMERIC 2
  256. #define SQL_DECIMAL 3
  257. #define SQL_INTEGER 4
  258. #define SQL_SMALLINT 5
  259. #define SQL_FLOAT 6
  260. #define SQL_REAL 7
  261. #define SQL_DOUBLE 8
  262. #if (ODBCVER >= 0x0300)
  263. #define SQL_DATETIME 9
  264. #endif
  265. #define SQL_VARCHAR 12
  266. / One-parameter shortcuts for date/time data types /
  267. #if (ODBCVER >= 0x0300)
  268. #define SQL_TYPE_DATE 91
  269. #define SQL_TYPE_TIME 92
  270. #define SQL_TYPE_TIMESTAMP 93
  271. #define SQL_UNICODE (-95)
  272. #define SQL_UNICODE_VARCHAR (-96)
  273. #define SQL_UNICODE_LONGVARCHAR (-97)
  274. */
  275. function ODBCTypes($t)
  276. {
  277. switch ((integer)$t) {
  278. case 1:
  279. case 12:
  280. case 0:
  281. case -95:
  282. case -96:
  283. return 'C';
  284. case -97:
  285. case -1: //text
  286. return 'X';
  287. case -4: //image
  288. return 'B';
  289. case 9:
  290. case 91:
  291. return 'D';
  292. case 10:
  293. case 11:
  294. case 92:
  295. case 93:
  296. return 'T';
  297. case 4:
  298. case 5:
  299. case -6:
  300. return 'I';
  301. case -11: // uniqidentifier
  302. return 'R';
  303. case -7: //bit
  304. return 'L';
  305. default:
  306. return 'N';
  307. }
  308. }
  309. function &MetaColumns($table)
  310. {
  311. global $ADODB_FETCH_MODE;
  312. $false = false;
  313. if ($this->uCaseTables) $table = strtoupper($table);
  314. $schema = '';
  315. $this->_findschema($table,$schema);
  316. $savem = $ADODB_FETCH_MODE;
  317. $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
  318. /*if (false) { // after testing, confirmed that the following does not work becoz of a bug
  319. $qid2 = odbc_tables($this->_connectionID);
  320. $rs = new ADORecordSet_odbc($qid2);
  321. $ADODB_FETCH_MODE = $savem;
  322. if (!$rs) return false;
  323. $rs->_has_stupid_odbc_fetch_api_change = $this->_has_stupid_odbc_fetch_api_change;
  324. $rs->_fetch();
  325. while (!$rs->EOF) {
  326. if ($table == strtoupper($rs->fields[2])) {
  327. $q = $rs->fields[0];
  328. $o = $rs->fields[1];
  329. break;
  330. }
  331. $rs->MoveNext();
  332. }
  333. $rs->Close();
  334. $qid = odbc_columns($this->_connectionID,$q,$o,strtoupper($table),'%');
  335. } */
  336. switch ($this->databaseType) {
  337. case 'access':
  338. case 'vfp':
  339. $qid = odbc_columns($this->_connectionID);#,'%','',strtoupper($table),'%');
  340. break;
  341. case 'db2':
  342. $colname = "%";
  343. $qid = odbc_columns($this->_connectionID, "", $schema, $table, $colname);
  344. break;
  345. default:
  346. $qid = @odbc_columns($this->_connectionID,'%','%',strtoupper($table),'%');
  347. if (empty($qid)) $qid = odbc_columns($this->_connectionID);
  348. break;
  349. }
  350. if (empty($qid)) return $false;
  351. $rs =& new ADORecordSet_odbc($qid);
  352. $ADODB_FETCH_MODE = $savem;
  353. if (!$rs) return $false;
  354. $rs->_has_stupid_odbc_fetch_api_change = $this->_has_stupid_odbc_fetch_api_change;
  355. $rs->_fetch();
  356. $retarr = array();
  357. /*
  358. $rs->fields indices
  359. 0 TABLE_QUALIFIER
  360. 1 TABLE_SCHEM
  361. 2 TABLE_NAME
  362. 3 COLUMN_NAME
  363. 4 DATA_TYPE
  364. 5 TYPE_NAME
  365. 6 PRECISION
  366. 7 LENGTH
  367. 8 SCALE
  368. 9 RADIX
  369. 10 NULLABLE
  370. 11 REMARKS
  371. */
  372. while (!$rs->EOF) {
  373. // adodb_pr($rs->fields);
  374. if (strtoupper(trim($rs->fields[2])) == $table && (!$schema || strtoupper($rs->fields[1]) == $schema)) {
  375. $fld = new ADOFieldObject();
  376. $fld->name = $rs->fields[3];
  377. $fld->type = $this->ODBCTypes($rs->fields[4]);
  378. // ref: http://msdn.microsoft.com/library/default.asp?url=/archive/en-us/dnaraccgen/html/msdn_odk.asp
  379. // access uses precision to store length for char/varchar
  380. if ($fld->type == 'C' or $fld->type == 'X') {
  381. if ($this->databaseType == 'access')
  382. $fld->max_length = $rs->fields[6];
  383. else if ($rs->fields[4] <= -95) // UNICODE
  384. $fld->max_length = $rs->fields[7]/2;
  385. else
  386. $fld->max_length = $rs->fields[7];
  387. } else
  388. $fld->max_length = $rs->fields[7];
  389. $fld->not_null = !empty($rs->fields[10]);
  390. $fld->scale = $rs->fields[8];
  391. $retarr[strtoupper($fld->name)] = $fld;
  392. } else if (sizeof($retarr)>0)
  393. break;
  394. $rs->MoveNext();
  395. }
  396. $rs->Close(); //-- crashes 4.03pl1 -- why?
  397. if (empty($retarr)) $retarr = false;
  398. return $retarr;
  399. }
  400. function Prepare($sql)
  401. {
  402. if (! $this->_bindInputArray) return $sql; // no binding
  403. $stmt = odbc_prepare($this->_connectionID,$sql);
  404. if (!$stmt) {
  405. // we don't know whether odbc driver is parsing prepared stmts, so just return sql
  406. return $sql;
  407. }
  408. return array($sql,$stmt,false);
  409. }
  410. /* returns queryID or false */
  411. function _query($sql,$inputarr=false)
  412. {
  413. GLOBAL $php_errormsg;
  414. if (isset($php_errormsg)) $php_errormsg = '';
  415. $this->_error = '';
  416. if ($inputarr) {
  417. if (is_array($sql)) {
  418. $stmtid = $sql[1];
  419. } else {
  420. $stmtid = odbc_prepare($this->_connectionID,$sql);
  421. if ($stmtid == false) {
  422. $this->_errorMsg = isset($php_errormsg) ? $php_errormsg : '';
  423. return false;
  424. }
  425. }
  426. if (! odbc_execute($stmtid,$inputarr)) {
  427. //@odbc_free_result($stmtid);
  428. if ($this->_haserrorfunctions) {
  429. $this->_errorMsg = odbc_errormsg();
  430. $this->_errorCode = odbc_error();
  431. }
  432. return false;
  433. }
  434. } else if (is_array($sql)) {
  435. $stmtid = $sql[1];
  436. if (!odbc_execute($stmtid)) {
  437. //@odbc_free_result($stmtid);
  438. if ($this->_haserrorfunctions) {
  439. $this->_errorMsg = odbc_errormsg();
  440. $this->_errorCode = odbc_error();
  441. }
  442. return false;
  443. }
  444. } else
  445. $stmtid = odbc_exec($this->_connectionID,$sql);
  446. $this->_lastAffectedRows = 0;
  447. if ($stmtid) {
  448. if (@odbc_num_fields($stmtid) == 0) {
  449. $this->_lastAffectedRows = odbc_num_rows($stmtid);
  450. $stmtid = true;
  451. } else {
  452. $this->_lastAffectedRows = 0;
  453. odbc_binmode($stmtid,$this->binmode);
  454. odbc_longreadlen($stmtid,$this->maxblobsize);
  455. }
  456. if ($this->_haserrorfunctions) {
  457. $this->_errorMsg = '';
  458. $this->_errorCode = 0;
  459. } else
  460. $this->_errorMsg = isset($php_errormsg) ? $php_errormsg : '';
  461. } else {
  462. if ($this->_haserrorfunctions) {
  463. $this->_errorMsg = odbc_errormsg();
  464. $this->_errorCode = odbc_error();
  465. } else
  466. $this->_errorMsg = isset($php_errormsg) ? $php_errormsg : '';
  467. }
  468. return $stmtid;
  469. }
  470. /*
  471. Insert a null into the blob field of the table first.
  472. Then use UpdateBlob to store the blob.
  473. Usage:
  474. $conn->Execute('INSERT INTO blobtable (id, blobcol) VALUES (1, null)');
  475. $conn->UpdateBlob('blobtable','blobcol',$blob,'id=1');
  476. */
  477. function UpdateBlob($table,$column,$val,$where,$blobtype='BLOB')
  478. {
  479. return $this->Execute("UPDATE $table SET $column=? WHERE $where",array($val)) != false;
  480. }
  481. // returns true or false
  482. function _close()
  483. {
  484. $ret = @odbc_close($this->_connectionID);
  485. $this->_connectionID = false;
  486. return $ret;
  487. }
  488. function _affectedrows()
  489. {
  490. return $this->_lastAffectedRows;
  491. }
  492. }
  493. /*--------------------------------------------------------------------------------------
  494. Class Name: Recordset
  495. --------------------------------------------------------------------------------------*/
  496. class ADORecordSet_odbc extends ADORecordSet {
  497. var $bind = false;
  498. var $databaseType = "odbc";
  499. var $dataProvider = "odbc";
  500. var $useFetchArray;
  501. var $_has_stupid_odbc_fetch_api_change;
  502. function ADORecordSet_odbc($id,$mode=false)
  503. {
  504. if ($mode === false) {
  505. global $ADODB_FETCH_MODE;
  506. $mode = $ADODB_FETCH_MODE;
  507. }
  508. $this->fetchMode = $mode;
  509. $this->_queryID = $id;
  510. // the following is required for mysql odbc driver in 4.3.1 -- why?
  511. $this->EOF = false;
  512. $this->_currentRow = -1;
  513. //$this->ADORecordSet($id);
  514. }
  515. // returns the field object
  516. function &FetchField($fieldOffset = -1)
  517. {
  518. $off=$fieldOffset+1; // offsets begin at 1
  519. $o= new ADOFieldObject();
  520. $o->name = @odbc_field_name($this->_queryID,$off);
  521. $o->type = @odbc_field_type($this->_queryID,$off);
  522. $o->max_length = @odbc_field_len($this->_queryID,$off);
  523. if (ADODB_ASSOC_CASE == 0) $o->name = strtolower($o->name);
  524. else if (ADODB_ASSOC_CASE == 1) $o->name = strtoupper($o->name);
  525. return $o;
  526. }
  527. /* Use associative array to get fields array */
  528. function Fields($colname)
  529. {
  530. if ($this->fetchMode & ADODB_FETCH_ASSOC) return $this->fields[$colname];
  531. if (!$this->bind) {
  532. $this->bind = array();
  533. for ($i=0; $i < $this->_numOfFields; $i++) {
  534. $o = $this->FetchField($i);
  535. $this->bind[strtoupper($o->name)] = $i;
  536. }
  537. }
  538. return $this->fields[$this->bind[strtoupper($colname)]];
  539. }
  540. function _initrs()
  541. {
  542. global $ADODB_COUNTRECS;
  543. $this->_numOfRows = ($ADODB_COUNTRECS) ? @odbc_num_rows($this->_queryID) : -1;
  544. $this->_numOfFields = @odbc_num_fields($this->_queryID);
  545. // some silly drivers such as db2 as/400 and intersystems cache return _numOfRows = 0
  546. if ($this->_numOfRows == 0) $this->_numOfRows = -1;
  547. //$this->useFetchArray = $this->connection->useFetchArray;
  548. $this->_has_stupid_odbc_fetch_api_change = ADODB_PHPVER >= 0x4200;
  549. }
  550. function _seek($row)
  551. {
  552. return false;
  553. }
  554. // speed up SelectLimit() by switching to ADODB_FETCH_NUM as ADODB_FETCH_ASSOC is emulated
  555. function &GetArrayLimit($nrows,$offset=-1)
  556. {
  557. if ($offset <= 0) {
  558. $rs =& $this->GetArray($nrows);
  559. return $rs;
  560. }
  561. $savem = $this->fetchMode;
  562. $this->fetchMode = ADODB_FETCH_NUM;
  563. $this->Move($offset);
  564. $this->fetchMode = $savem;
  565. if ($this->fetchMode & ADODB_FETCH_ASSOC) {
  566. $this->fields =& $this->GetRowAssoc(ADODB_ASSOC_CASE);
  567. }
  568. $results = array();
  569. $cnt = 0;
  570. while (!$this->EOF && $nrows != $cnt) {
  571. $results[$cnt++] = $this->fields;
  572. $this->MoveNext();
  573. }
  574. return $results;
  575. }
  576. function MoveNext()
  577. {
  578. if ($this->_numOfRows != 0 && !$this->EOF) {
  579. $this->_currentRow++;
  580. if ($this->_has_stupid_odbc_fetch_api_change)
  581. $rez = @odbc_fetch_into($this->_queryID,$this->fields);
  582. else {
  583. $row = 0;
  584. $rez = @odbc_fetch_into($this->_queryID,$row,$this->fields);
  585. }
  586. if ($rez) {
  587. if ($this->fetchMode & ADODB_FETCH_ASSOC) {
  588. $this->fields =& $this->GetRowAssoc(ADODB_ASSOC_CASE);
  589. }
  590. return true;
  591. }
  592. }
  593. $this->fields = false;
  594. $this->EOF = true;
  595. return false;
  596. }
  597. function _fetch()
  598. {
  599. if ($this->_has_stupid_odbc_fetch_api_change)
  600. $rez = @odbc_fetch_into($this->_queryID,$this->fields);
  601. else {
  602. $row = 0;
  603. $rez = @odbc_fetch_into($this->_queryID,$row,$this->fields);
  604. }
  605. if ($rez) {
  606. if ($this->fetchMode & ADODB_FETCH_ASSOC) {
  607. $this->fields =& $this->GetRowAssoc(ADODB_ASSOC_CASE);
  608. }
  609. return true;
  610. }
  611. $this->fields = false;
  612. return false;
  613. }
  614. function _close()
  615. {
  616. return @odbc_free_result($this->_queryID);
  617. }
  618. }
  619. ?>