diff options
| author | Marcus Boerger <helly@php.net> | 2003-05-01 23:28:28 +0000 |
|---|---|---|
| committer | Marcus Boerger <helly@php.net> | 2003-05-01 23:28:28 +0000 |
| commit | b5a70a72d13a3951317466cb8a671eafffffc359 (patch) | |
| tree | 09f1ec55eca84f6c7bd183415b3999e78311d703 /ext/spl/examples | |
| parent | 0d46a490f7abc6039fd98afc3c0a62ce111551c8 (diff) | |
| download | php-git-b5a70a72d13a3951317466cb8a671eafffffc359.tar.gz | |
Add spl extension
Diffstat (limited to 'ext/spl/examples')
| -rwxr-xr-x | ext/spl/examples/dba_dump.php | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/ext/spl/examples/dba_dump.php b/ext/spl/examples/dba_dump.php new file mode 100755 index 0000000000..d32f1761c9 --- /dev/null +++ b/ext/spl/examples/dba_dump.php @@ -0,0 +1,72 @@ +<?php + +/* dba dump utility + * + * Usage php dba_dump <file> <handler> + * + * Note: configure with --enable-dba + */ + +class dba_reader implements spl::iterator { + + public $db = NULL; + + function __construct($file, $handler) { + $this->db = dba_open($file, 'r', $handler); + } + + function new_iterator() { + return new dba_iter($this); + } + + function __destruct() { + if ($this->db) { + dba_close($this->db); + } + } +} + +class dba_iter implements spl::sequence_assoc { + + private $obj; + private $key = NULL; + private $val = NULL; + + function __construct($obj) { + $this->obj = $obj; + } + + function reset() { + if ($this->obj->db) { + $this->key = dba_firstkey($this->obj->db); + } + } + + function elem() { + return $this->val; + } + + function next() { + $this->key = dba_nextkey($this->obj->db); + } + + function more() { + if ($this->obj->db && $this->key !== false) { + $this->val = dba_fetch($this->key, $this->obj->db); + return true; + } else { + return false; + } + } + + function key() { + return $this->key; + } +} + +$db = new dba_reader($argv[1], $argv[2]); +foreach($db as $key => $val) { + echo "'$key' => '$val'\n"; +} + +?>
\ No newline at end of file |
