-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase.php
More file actions
236 lines (186 loc) · 5.68 KB
/
database.php
File metadata and controls
236 lines (186 loc) · 5.68 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
<?php
class Database {
public $host;
public $dbname;
public $username;
public $password;
public $conn;
public function __construct($host, $dbname, $username, $password) {
$this->host = $host;
$this->dbname = $dbname;
$this->username = $username;
$this->password = $password;
$this->connectToDatabase();
// $this->connectToDatabase();
}
public function connectToDatabase() {
try {
$this->conn = new PDO("mysql:host={$this->host};port=3306;dbname={$this->dbname}", $this->username, $this->password);
$this->conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
return $this->conn;
} catch (PDOException $e) {
echo "Server Connection failed: " . $e->getMessage();
}
}
// public function connectToDatabase() {
// try {
// $this->conn->exec("USE {$this->dbname}");
// } catch (PDOException $e) {
// echo "Database Connection failed: " . $e->getMessage();
// }
// }
public function closeConnection() {
$this->conn = null;
}
// public function getConnections() {
// return $this->conn;
// }
}
class Employers {
private $db;
public function __construct($db) {
$this->db = $db;
}
public function createTable() {
$sql = "
CREATE TABLE IF NOT EXISTS employers (
Type ENUM('Admin', 'Agent'),
`Full name` VARCHAR(255),
`Date of birth` DATE,
`employer ID` INT PRIMARY KEY,
Place VARCHAR(255),
Password VARCHAR(255)
)
";
$this->db->connectToServer()->exec($sql);
}
}
class Clients {
private $db;
// Clients table columns as class properties
public function __construct($db) {
$this->db = $db;
}
public function createTable() {
$sql = "
CREATE TABLE IF NOT EXISTS clients (
`Full name` VARCHAR(255),
`Client ID` INT PRIMARY KEY,
`Date of birth` DATE,
`phone number` VARCHAR(20),
email VARCHAR(255),
address VARCHAR(255),
`social ID` VARCHAR(20),
Category VARCHAR(255),
`Profile Picture` VARCHAR(255),
Password VARCHAR(255)
)
";
$this->db->connectToServer()->exec($sql);
}
}
class Subscription {
private $db;
public function __construct($db) {
$this->db = $db;
}
public function createTable() {
$sql = "
CREATE TABLE IF NOT EXISTS subscription (
`Client ID` INT,
FOREIGN KEY (`Client ID`) REFERENCES clients(`Client ID`),
Status ENUM('inhold','Valid', 'Outdated', 'Lost','Ruined'),
`Date of demand` DATE,
`Date Acceptance` DATE,
`Expiration` DATE
)
";
$this->db->connectToServer()->exec($sql);
}
}
class Compliments {
private $db;
public function __construct($db) {
$this->db = $db;
}
public function createTable() {
$sql = "
CREATE TABLE IF NOT EXISTS compliments (
`Compliment ID` INT PRIMARY KEY,
`Client ID` INT,
FOREIGN KEY (`Client ID`) REFERENCES clients(`Client ID`),
`employer ID` INT,
FOREIGN KEY (`employer ID`) REFERENCES employers(`employer ID`),
`Status` ENUM('checked', 'unchecked'),
Message TEXT,
`Subject` VARCHAR(255)
)
";
$this->db->connectToServer()->exec($sql);
}
}
class AdditionalItems {
private $db;
public function __construct($db) {
$this->db = $db;
}
public function createTable() {
$sql = "
CREATE TABLE IF NOT EXISTS additional_items (
`name` VARCHAR(255),
content TEXT
)
";
$this->db->connectToServer()->exec($sql);
}
}
class Refuses {
private $db;
public function __construct($db) {
$this->db = $db;
}
public function createTable() {
$sql = "
CREATE TABLE IF NOT EXISTS Refuses (
`Client ID` INT,
FOREIGN KEY (`Client ID`) REFERENCES clients(`Client ID`),
message TEXT
)
";
$this->db->connectToServer()->exec($sql);
}
}
class feedbacks {
private $db;
public function __construct($db) {
$this->db = $db;
}
public function createTable() {
$sql = "
CREATE TABLE IF NOT EXISTS feedbacks (
FeedbackID INT PRIMARY KEY AUTO_INCREMENT,
`Client ID` INT,
Rating INT,
Comments TEXT,
FOREIGN KEY (`Client ID`) REFERENCES clients(`Client ID`)
);
";
$this->db->connectToServer()->exec($sql);
}
}
// $database = new Database("loaclhost", "Setram", "root", "");
// $employersTable = new Employers($database);
// $clientsTable = new Clients($database);
// $subscriptionTable = new Subscription($database);
// $complimentsTable = new Compliments($database);
// $additionalItemsTable = new AdditionalItems($database);
// $add = new Refuses($database);
// $feedbacks = new feedbacks($database);
// $employersTable->createTable();
// $clientsTable->createTable();
// $subscriptionTable->createTable();
// $complimentsTable->createTable();
// $additionalItemsTable->createTable();
// $add->createTable();
// $feedbacks->createTable();
?>