-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathservice.php
More file actions
104 lines (82 loc) · 2.42 KB
/
Copy pathservice.php
File metadata and controls
104 lines (82 loc) · 2.42 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<?php
include_once 'db_connect.php';
function getNewId($table){
global $gbd;
$sql = "SELECT max(id) FROM $table";
$gsent = $gbd->prepare($sql);
$gsent->execute();
$result = $gsent->fetch();
return $result[0]+1;
}
function getAllNotes(){
global $gbd;
$sql = 'SELECT * from notes';
$gsent = $gbd->prepare($sql);
$gsent->execute();
$result = $gsent->fetchAll();
return $result;
};
function getNoteById($id){
global $gbd;
$sql = 'SELECT * from notes where id = ?';
$gsent = $gbd->prepare($sql);
$gsent->execute(array($id));
$result = $gsent->fetch();
return $result;
};
function getColorClassOfNote($id){
global $gbd;
$sql = 'SELECT colors.bootstrap from colors INNER JOIN notes where notes.id = ? AND notes.color = colors.id ';
$gsent = $gbd->prepare($sql);
$gsent->execute(array($id));
$result = $gsent->fetch();
return $result[0];
};
function getColorIdOfNote($id){
global $gbd;
$sql = 'SELECT colors.id from colors INNER JOIN notes where notes.id = ? AND notes.color = colors.id ';
$gsent = $gbd->prepare($sql);
$gsent->execute(array($id));
$result = $gsent->fetch();
return $result[0];
};
function getAllColors(){
global $gbd;
$sql = 'SELECT * from colors';
$gsent = $gbd->prepare($sql);
$gsent->execute();
$result = $gsent->fetchAll();
return $result;
};
function insertNote($title, $description, $color){
global $gbd;
try{
$newId = getNewId("notes");
$sql = "INSERT INTO notes (title, description, color, id) VALUES (?, ?, ?, ?)";
$gsent = $gbd->prepare($sql);
$gsent->execute(array($title, $description, $color, $newId));
} catch(PDOException $e) {
echo $sql . "<br>" . $e->getMessage();
}
};
function updateNote($id, $title, $description, $color){
global $gbd;
try{
$sql = "UPDATE notes SET title = ?, description = ?, color = ? WHERE id = ?";
$gsent = $gbd->prepare($sql);
$gsent->execute(array($title, $description, $color, $id));
} catch(PDOException $e) {
echo $sql . "<br>" . $e->getMessage();
}
};
function deleteNote($id){
global $gbd;
try{
$sql = "DELETE FROM notes WHERE id = ?";
$gsent = $gbd->prepare($sql);
$gsent->execute(array($id));
} catch(PDOException $e) {
echo $sql . "<br>" . $e->getMessage();
}
};
?>