PageRenderTime 55ms CodeModel.GetById 30ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/rdfapi-php/api/util/adodb/adodb-iterator.inc.php

https://github.com/komagata/plnet
PHP | 83 lines | 47 code | 17 blank | 19 comment | 0 complexity | d6a2c87ad67b475342046c0a7533c4fa MD5 | raw file
Possible License(s): LGPL-2.1
  1. <?php
  2. /*
  3. V4.52 10 Aug 2004 (c) 2000-2004 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. function __toString()
  56. {
  57. include_once(ADODB_DIR.'/toexport.inc.php');
  58. return _adodb_export($this,',',',',false,true);
  59. }
  60. }
  61. ?>