/framework/core/db/DbMysqlResult.php

http://zoop.googlecode.com/ · PHP · 70 lines · 61 code · 9 blank · 0 comment · 8 complexity · 4e7657eb95fded6fea01341ab9fd5c9e MD5 · raw file

  1. <?php
  2. class DbMysqlResult extends DbResultSet
  3. {
  4. private $cur;
  5. private $max;
  6. function __construct($link, $res)
  7. {
  8. parent::__construct($link, $res);
  9. if (gettype($res) == "boolean")
  10. {
  11. $this->res = null;
  12. $this->cur = 0;
  13. $this->max = 0;
  14. }
  15. else
  16. {
  17. $this->cur = 0;
  18. $this->max = mysql_num_rows($this->res) - 1;
  19. }
  20. }
  21. function numRows()
  22. {
  23. return $this->max + 1;
  24. }
  25. function rewind()
  26. {
  27. $this->cur = 0;
  28. }
  29. function current()
  30. {
  31. if($this->max == -1)
  32. return false;
  33. mysql_data_seek($this->res, $this->cur);
  34. return mysql_fetch_assoc($this->res);
  35. }
  36. function key()
  37. {
  38. return $this->cur;
  39. }
  40. function next()
  41. {
  42. $this->cur++;
  43. if($this->cur > $this->max)
  44. return false;
  45. mysql_data_seek($this->res, $this->cur);
  46. return mysql_fetch_assoc($this->res);
  47. }
  48. function valid()
  49. {
  50. if($this->cur > $this->max)
  51. return false;
  52. return true;
  53. }
  54. function affectedRows()
  55. {
  56. if ($this->res == null)
  57. return -1;
  58. else
  59. return mysql_affected_rows($this->link);
  60. }
  61. }