/framework/core/db/DbTable.php

http://zoop.googlecode.com/ · PHP · 78 lines · 55 code · 12 blank · 11 comment · 1 complexity · a2d2762030504e813631271ffce0ba2a MD5 · raw file

  1. <?php
  2. class DbTable extends Object implements Iterator
  3. {
  4. public $name;
  5. private $fields;
  6. private $conn;
  7. function __construct($conn, $name)
  8. {
  9. // var_dump($conn) . '<br>';
  10. $this->conn = $conn;
  11. // var_dump($this->conn);
  12. $this->name = $name;
  13. // get rid of fields and just use columns
  14. $this->addGetter('fields');
  15. $this->addGetter('columns');
  16. }
  17. // change this to getColumns
  18. public function getFields()
  19. {
  20. if(!$this->fields)
  21. {
  22. $this->fields = array();
  23. foreach($this->conn->getTableFieldInfo($this->name) as $fieldInfo)
  24. {
  25. $this->fields[] = new DbField($fieldInfo);
  26. }
  27. }
  28. return $this->fields;
  29. }
  30. // alias for getColumns (this is the prefered method to use)
  31. public function getColumns()
  32. {
  33. return $this->getFields();
  34. }
  35. //
  36. // begin iterator functions
  37. //
  38. public function rewind()
  39. {
  40. $this->getFields();
  41. reset($this->fields);
  42. }
  43. public function current()
  44. {
  45. $var = current($this->fields);
  46. return $var;
  47. }
  48. public function key()
  49. {
  50. $var = key($this->fields);
  51. return $var;
  52. }
  53. public function next()
  54. {
  55. $var = next($this->fields);
  56. return $var;
  57. }
  58. public function valid()
  59. {
  60. $var = $this->current() !== false;
  61. return $var;
  62. }
  63. //
  64. // end iterator functions
  65. //
  66. }