-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathindex.php
30 lines (24 loc) · 802 Bytes
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<?php
include("library/json-db.class.php");
// Instantiate the class with default name (db.json)
$db = new DB();
// You can also instantiate another db with a custom name (custom-name.json)
$db2 = new DB("custom-name");
$data = array(
"id" => 1,
"name" => "John",
"surname" => "Doe"
);
// Add a new field to the db, passing the data (an array) and the key (in this case, the id)
$db->insert($data, $data['id']);
// Show one single result based on the key
$result = $db->getSingle($data['id']);
// Show several results based on array query (in this case, all the fields with name: "John" and surname: "Doe")
$query = [
"name" => "John",
"surname" => "Doe"
];
$result2 = $db->getList($query);
// Remove the row from the db based on the key you pass
$db->delete($data['id']);
?>