first version

This commit is contained in:
Grzegorz Surmann 2024-09-02 19:27:15 +02:00
commit 2335cead8e
5 changed files with 37 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
db/

1
README.md Normal file
View File

@ -0,0 +1 @@
A small stateless DB for PHP with data saved in JSON format.

10
demo.php Normal file
View File

@ -0,0 +1,10 @@
<?php
require_once("inc/config.inc.php");
require_once("inc/Class.PHPJSONDB.inc.php");
$item1=array("test","test2","test3","test4","test5");
PJDB::put('db1','table1','item1',$item1);
print_r(PJDB::get('db1','table1','item1'));

View File

@ -0,0 +1,22 @@
<?php
class PHPJSONDB {
static function put($db,$table,$item,$data) {
global $phpjsondb_dbpath;
if ( !file_exists($phpjsondb_dbpath."/".$db."/".$table."/".md5($item).".data") ) {
@mkdir($phpjsondb_dbpath."/".$db."/".$table,0755,TRUE);
file_put_contents($phpjsondb_dbpath."/".$db."/".$table."/".md5($item).".json",json_encode($data));
}
return TRUE;
}
static function get($db,$table,$item) {
global $phpjsondb_dbpath;
if ( file_exists($phpjsondb_dbpath."/".$db."/".$table."/".md5($item).".json") ) {
return json_decode(file_get_contents($phpjsondb_dbpath."/".$db."/".$table."/".md5($item).".json"));
}
return FALSE;
}
}
class PJDB extends PHPJSONDB {
}

3
inc/config.inc.php Normal file
View File

@ -0,0 +1,3 @@
<?php
$phpjsondb_dbpath="./db";