first version
This commit is contained in:
commit
2335cead8e
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
db/
|
1
README.md
Normal file
1
README.md
Normal file
@ -0,0 +1 @@
|
||||
A small stateless DB for PHP with data saved in JSON format.
|
10
demo.php
Normal file
10
demo.php
Normal 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'));
|
22
inc/Class.PHPJSONDB.inc.php
Normal file
22
inc/Class.PHPJSONDB.inc.php
Normal 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
3
inc/config.inc.php
Normal file
@ -0,0 +1,3 @@
|
||||
<?php
|
||||
|
||||
$phpjsondb_dbpath="./db";
|
Loading…
Reference in New Issue
Block a user