SPL-StandardPHPLibrary
dbaarray.inc
Go to the documentation of this file.
1 <?php
2 
12 if (!class_exists("DbaReader", false)) require_once("dbareader.inc");
13 
19 class DbaArray extends DbaReader implements ArrayAccess
20 {
21 
28  function __construct($file, $handler)
29  {
30  $this->db = dba_popen($file, "c", $handler);
31  if (!$this->db) {
32  throw new exception("Databse could not be opened");
33  }
34  }
35 
39  function __destruct()
40  {
41  parent::__destruct();
42  }
43 
50  function offsetGet($name)
51  {
52  $data = dba_fetch($name, $this->db);
53  if($data) {
54  //return unserialize($data);
55  return $data;
56  }
57  else
58  {
59  return NULL;
60  }
61  }
62 
69  function offsetSet($name, $value)
70  {
71  //dba_replace($name, serialize($value), $this->db);
72  dba_replace($name, $value, $this->db);
73  return $value;
74  }
75 
79  function offsetExists($name)
80  {
81  return dba_exists($name, $this->db);
82  }
83 
89  function offsetUnset($name)
90  {
91  return dba_delete($name, $this->db);
92  }
93 }
94 
95 ?>
Interface to override array access of objects.
Definition: spl.php:486
offsetGet($name)
Read an entry.
Definition: dbaarray.inc:50
offsetUnset($name)
Delete a key/value pair.
Definition: dbaarray.inc:89
__construct($file, $handler)
Open database $file with $handler in read only mode.
Definition: dbaarray.inc:28
This implements a DBA Iterator.
Definition: dbareader.inc:17
__destruct()
Close database.
Definition: dbaarray.inc:39
offsetExists($name)
Definition: dbaarray.inc:79
offsetSet($name, $value)
Set an entry.
Definition: dbaarray.inc:69
This implements a DBA Array.
Definition: dbaarray.inc:19