dbjson : if the database is empty, allow to read it without error

git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@2583 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
2016-02-27 16:54:46 +00:00
parent 24f99e6a69
commit 09c859ee98

View File

@@ -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 !