PageRenderTime 44ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/05_Desarrollo/lib/adodb/adodb-iterator.inc.php

https://bitbucket.org/SerafinAkatsuki/consultorio
PHP | 85 lines | 47 code | 18 blank | 20 comment | 0 complexity | 587d56587ad7088368d55dec06f969b5 MD5 | raw file
Possible License(s): LGPL-2.1
  1. <?php
  2. /*
  3. V4.990 11 July 2008 (c) 2000-2008 John Lim (jlim#natsoft.com). 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. ?>