JSON Database
This Class works on PHP 8 or above.
- File - path to file (create new file, if file not exists)
- (optional) Structure - array of colums
require "jData.php";
$jd = new jData("db.json",["key","value"]);
$jd->insert(["keyName","0"]);
/*
+----+-----------+------------+
| id | key | value |
+----+-----------+------------+
| 0 | keyName | 0 (string) |
+----+-----------+------------+
*/Returns false if structures (from db and script) doesn't equal.
- Colum|ID - name of colum for search or direct select by id (returns whole table if null).
- Value - string/bool/int for searching (if first argument was colum name). Returns object (if single result) or array (if multiple results).
$sel = $jd->select(); // select whole table
$sel = $jd->select(0); // select data where id = 0
$sel = $jd->select("key","keyName"); // select data where key = keyNameSaves id of last result (ONLY with single result) Returns false if colum with that name doesn't exists or search value null (if first argument was colum name).
- Values - array of values for inserting
$jd->insert(["keyName","0"]);Returns ID of this data.
Returns false if size of colums and values doesn't equal.
- ID - id of data or Values (if id was saved after select).
- Values - array of values for inserting
$sel = $jd->select(0);
$sel->key = "otherName";
$jd->update($sel); // using selected id
$jd->update(0,$sel);Returns ID of this data.
Returns false if size of colums and values doesn't equal or ID not found.
- (optional) ID - id of data.
$jd->select(0);
$jd->delete(); // using selected id
$jd->delete(0);Return boolean result of searching by ID.