-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreateDatabase.php
67 lines (51 loc) · 1.8 KB
/
createDatabase.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
62
63
64
65
66
67
<?php
define('DB_NAME', 'rotas');
define('DB_USER', 'root');
define('DB_PASSWORD', '');
define('DB_HOST', 'localhost');
$conn = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
if ($conn->connect_error) die($conn->connect_error);
echo 'Connected successfully!';
$date = "CREATE TABLE date (
date_id int NOT NULL AUTO_INCREMENT,
fulldate date NOT NULL,
year int NOT NULL,
month varchar(10) NOT NULL,
day varchar(10) NOT NULL,
PRIMARY KEY (date_id)
)";
//CONSTRAINT Date_pk PRIMARY KEY (Date_id)
$result = $conn->query($date);
if (!$result) die ("Database access failed: " . $conn->error);
$employee = "CREATE TABLE employee (
employee_id int NOT NULL AUTO_INCREMENT,
firstName varchar(30) NOT NULL,
lastName varchar(30) NOT NULL,
section varchar(20) NOT NULL,
contractHours int NOT NULL,
PRIMARY KEY (employee_id)
)";
$result = $conn->query($employee);
if (!$result) die ("Database access failed: " . $conn->error);
//CONSTRAINT Employee_pk PRIMARY KEY (Employee_id)
$schedule = "CREATE TABLE schedule (
shift_id int NOT NULL AUTO_INCREMENT,
employee_id int NOT NULL,
date_id int NOT NULL,
start_shift decimal(5,3) NOT NULL,
end_shift decimal(5,3) NOT NULL,
PRIMARY KEY (shift_id)
)";
//CONSTRAINT Schedule_pk PRIMARY KEY (Shift_id)
/*foreign keys
-- Reference: Schedule_Date (table: Schedule)
--ALTER TABLE Schedule ADD CONSTRAINT Schedule_Date FOREIGN KEY Schedule_Date (Date_id)
-- REFERENCES Date (Date_id);
-- Reference: Schedule_Employee (table: Schedule)
--ALTER TABLE Schedule ADD CONSTRAINT Schedule_Employee FOREIGN KEY Schedule_Employee (Employee_id)
-- REFERENCES Employee (Employee_id);
-- End of file.////*/
$result = $conn->query($schedule);
if (!$result) die ("Database access failed: " . $conn->error);
echo 'Connected created tables!';
?>