-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.php
37 lines (32 loc) · 1.11 KB
/
test.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
31
32
33
34
35
36
37
<?php
require "json_database.php";
$db = new JsonDatabase();
try {
$db->create_database("db");
$db->create_table("table");
}
catch (Exception $e) {
echo "There is no need to create these directories an folders again\n";
}
$db->connect_database("db");
// clear the table for testing
$db->remove("table",(object)[]);
// create some data
$db->insert("table",
(object)['a'=>"a value for a",'id'=>0, 'flag'=>true]);
$db->insert("table",
[
(object)['id'=>1,'b'=>'a value for b'],
(object)['id'=>2,'a'=>'another value a','b'=>'another value b','flag'=>true],
(object)['id'=>3,'a'=>'another value a','b'=>'another value b','flag'=>false],
(object)['a'=>'another value a','b'=>'another value b','flag'=>false]
]);
$db->remove("table",(object)['id'=>1]);
$db->update("table", (object)['a'=>'flagged','f'=>'new column'] , (object)['flag'=>true]);
echo "Read a single line from a table:\n";
print_r($db->get_row("table", (object)['id'=>3]));
echo "Read a sub table according to a condition:\n";
$db_copy = new JsonDatabaseCopy();
$db_copy->connect_database("db");
$db_copy->printPartialTable("table",(object)['a'=>'flagged'])
?>