-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.php
61 lines (52 loc) · 1.21 KB
/
example.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
require_once "vendor/autoload.php";
use Lib\DB;
use Lib\ENV;
use Models\User;
DB::config((new ENV)->read());
dumpl("PDO", DB::pdo());
// WHERE
$user = new User;
$result = $user->where("{{id}} = :id AND {{email}} = :email", [
":id" => 2,
":email" => "[email protected]"
]);
dumpl("WHERE", $result);
// FIND ID
$user = new User;
$result = $user->findId(1);
dumpl("FIND ID", $result);
if ($result === null) {
// INSERT
$user = new User;
$user->name = "Matheus";
$user->email = "[email protected]";
$user->age = 23;
dumpl("INSERT", $user->save());
$user = new User;
$user->name = "Johann";
$user->email = "[email protected]";
$user->age = 23;
dumpl("INSERT", $user->save());
} else {
// UPDATE
$user = new User;
$user->id = 1;
$user->name = "Matheus Johann " . md5(rand(0, 9999999));
$user->age = $result->age + 1;
dumpl("UPDATE", $user->save());
if ($result->age == 25) {
// DELETE
$user = new User;
dumpl("DELETE", $user->delete(1));
}
}
// ALL
$user = new User;
$result = $user->all();
dumpl("ALL", $result);
if (count($result) > 3) {
// TRUNCATE
$user = new User;
dumpl("TRUNCATE", $user->truncate(true));
}