PageRenderTime 48ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/libraries/adodb.493a/adodb-iterator.inc.php

https://github.com/infused/retrospect-gds
PHP | 85 lines | 47 code | 18 blank | 20 comment | 0 complexity | 475ce2a517c33d4fd7956b8c8d54c9ca 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.
  8. Declares the ADODB Base Class for PHP5 "ADODB_BASE_RS", and supports iteration with
  9. the ADODB_Iterator class.
  10. $rs = $db->Execute("select * from adoxyz");
  11. foreach($rs as $k => $v) {
  12. echo $k; print_r($v); echo "<br>";
  13. }
  14. Iterator code based on http://cvs.php.net/cvs.php/php-src/ext/spl/examples/cachingiterator.inc?login=2
  15. */
  16. class ADODB_Iterator implements Iterator {
  17. private $rs;
  18. function __construct($rs)
  19. {
  20. $this->rs = $rs;
  21. }
  22. function rewind()
  23. {
  24. $this->rs->MoveFirst();
  25. }
  26. function valid()
  27. {
  28. return !$this->rs->EOF;
  29. }
  30. function key()
  31. {
  32. return $this->rs->_currentRow;
  33. }
  34. function current()
  35. {
  36. return $this->rs->fields;
  37. }
  38. function next()
  39. {
  40. $this->rs->MoveNext();
  41. }
  42. function __call($func, $params)
  43. {
  44. return call_user_func_array(array($this->rs, $func), $params);
  45. }
  46. function hasMore()
  47. {
  48. return !$this->rs->EOF;
  49. }
  50. }
  51. class ADODB_BASE_RS implements IteratorAggregate {
  52. function getIterator() {
  53. return new ADODB_Iterator($this);
  54. }
  55. /* this is experimental - i don't really know what to return... */
  56. function __toString()
  57. {
  58. include_once(ADODB_DIR.'/toexport.inc.php');
  59. return _adodb_export($this,',',',',false,true);
  60. }
  61. }
  62. ?>