diff --git a/dbjson.php b/dbjson.php index 731c790..68a1380 100644 --- a/dbjson.php +++ b/dbjson.php @@ -275,6 +275,8 @@ class dbjson if ($this->db === null) $this->db = $this->readDB (); $keys = array (); + if (! array_key_exists ($collection, $this->db)) + $this->db[$collection]["content"] = array (); foreach ($this->db[$collection]["content"] as $key=>$document) { if ($filter === array ()) @@ -384,7 +386,10 @@ class dbjson */ private function readDB () { - return json_decode (file_get_contents ($this->dbfile), true); + $res = json_decode (file_get_contents ($this->dbfile), true); + if ($res === null) + $res = array (); + return $res; } /** Write the dbfile with the provided data. This function don't do locks !