1
0
mirror of https://github.com/php/php-src.git synced 2026-03-27 09:42:22 +01:00
Files
archived-php-src/ext/spl/examples/dba_dump.php
Marcus Boerger f4d3111e8a Fix example
2003-06-22 12:57:53 +00:00

66 lines
1005 B
PHP
Executable File

<?php
/* dba dump utility
*
* Usage php dba_dump <file> <handler>
*
* Note: configure with --enable-dba
*
* (c) Marcus Boerger
*/
class dba_reader implements spl_sequence_assoc
{
private $db = NULL;
private $key = false;
private $val = false;
function __construct($file, $handler) {
$this->db = dba_open($file, 'r', $handler);
}
function __destruct() {
if ($this->db) {
dba_close($this->db);
}
}
function rewind() {
if ($this->db) {
$this->key = dba_firstkey($this->db);
}
}
function current() {
return $this->val;
}
function next() {
if ($this->db) {
$this->key = dba_nextkey($this->db);
if ($this->key !== false) {
$this->val = dba_fetch($this->key, $this->db);
}
}
}
function has_more() {
if ($this->db && $this->key !== false) {
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";
}
?>