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:
@@ -275,6 +275,8 @@ class dbjson
|
|||||||
if ($this->db === null)
|
if ($this->db === null)
|
||||||
$this->db = $this->readDB ();
|
$this->db = $this->readDB ();
|
||||||
$keys = array ();
|
$keys = array ();
|
||||||
|
if (! array_key_exists ($collection, $this->db))
|
||||||
|
$this->db[$collection]["content"] = array ();
|
||||||
foreach ($this->db[$collection]["content"] as $key=>$document)
|
foreach ($this->db[$collection]["content"] as $key=>$document)
|
||||||
{
|
{
|
||||||
if ($filter === array ())
|
if ($filter === array ())
|
||||||
@@ -384,7 +386,10 @@ class dbjson
|
|||||||
*/
|
*/
|
||||||
private function readDB ()
|
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 !
|
/** Write the dbfile with the provided data. This function don't do locks !
|
||||||
|
|||||||
Reference in New Issue
Block a user