Back to index

php5  5.3.10
dbareader.inc
Go to the documentation of this file.
00001 <?php
00002 
00017 class DbaReader implements Iterator
00018 {
00019 
00020        protected $db = NULL;
00021        private $key = false;
00022        private $val = false;
00023 
00030        function __construct($file, $handler) {
00031               if (!$this->db = dba_open($file, 'r', $handler)) {
00032                   throw new exception('Could not open file ' . $file);
00033               }
00034        }
00035        
00039        function __destruct() {
00040               dba_close($this->db);
00041        }
00042 
00046        function rewind() {
00047               $this->key = dba_firstkey($this->db);
00048               $this->fetch_data();
00049        }
00050 
00056        function next() {
00057               $this->key = dba_nextkey($this->db);
00058               $this->fetch_data();
00059        }
00060 
00064        private function fetch_data() {
00065               if ($this->key !== false) {
00066                      $this->val = dba_fetch($this->key, $this->db);
00067               }
00068        }
00069 
00073        function current() {
00074               return $this->val;
00075        }
00076 
00080        function valid() {
00081               if ($this->db && $this->key !== false) {
00082                      return true;
00083               } else {
00084                      return false;
00085               }
00086        }
00087 
00091        function key() {
00092               return $this->key;
00093        }
00094 }
00095 
00096 ?>