-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdbSetup.php
More file actions
255 lines (213 loc) · 6.84 KB
/
dbSetup.php
File metadata and controls
255 lines (213 loc) · 6.84 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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
<?php
// Create connection on Openshift machine
//$con=mysqli_connect("127.0.0.1","userERA","5THnhIwCoyCMtuA0");
$dbhost = getenv("MYSQL_SERVICE_HOST");
$dbport = getenv("MYSQL_SERVICE_PORT");
$dbuser = getenv("databaseuser");
$dbpwd = getenv("databasepassword");
$dbname = getenv("databasename");
$con = new mysqli($dbhost, $dbuser, $dbpwd, $dbname);
// Check connection
if (mysqli_connect_errno($con)){
echo "Failed to connect to MySQL: " . mysqli_connect_error() . "<br>";
}
// Create database
//$sql="create database IF NOT EXISTS tutorScheduler";
//if (mysqli_query($con,$sql)){
// echo "Database tutorScheduler created successfully <br>";
//}
//else {
// echo "Error creating database: " . mysqli_error($con) . "<br>";
//}
// Set database
//$sql="use tutorScheduler";
//if (mysqli_query($con,$sql)){
// echo "Database set successfully <br>";
//}
//else {
// echo "Error setting database: " . mysqli_error($con) . "<br>";
//}
// Drop employeeInfo if previously there
$sql="drop table if exists employeeInfo";
if(mysqli_query($con,$sql)){
echo "Deleted previously existing employeeInfo table <br>";
}
// Create employee info
$sql="create table employeeInfo (
PID INT NOT NULL AUTO_INCREMENT,
PRIMARY KEY (PID),
Fname VARCHAR(30), Lname VARCHAR(30), type VARCHAR(5))";
if (mysqli_query($con,$sql)){
echo "Table employeeInfo created successfully <br>";
}
else{
echo "Error creating table: " . mysqli_error($con) . "<br>";
}
// Populate employeeInfo with initial data
$sql="load data local infile './testEmployee.txt' into table employeeInfo
fields terminated by ','";
if (mysqli_query($con,$sql)){
echo "employeeInfo loaded successfully <br>";
}
else{
echo "Error loading data: " . mysqli_error($con) . "<br>";
}
// Drop hoursByDay if previously there
$sql="drop table if exists hoursByDay";
if(mysqli_query($con,$sql)){
echo "Deleted previously existing hoursByDay table <br>";
}
// Create hoursByDay
$sql="create table hoursByDay (
PID INT NOT NULL AUTO_INCREMENT,
PRIMARY KEY (PID,day),
day VARCHAR(15),
h00 INT, h01 INT, h02 INT, h03 INT, h04 INT, h05 INT, h06 INT, h07 INT,
h08 INT, h09 INT, h10 INT, h11 INT, h12 INT, h13 INT, h14 INT, h15 INT,
h16 INT, h17 INT, h18 INT, h19 INT, h20 INT, h21 INT, h22 INT, h23 INT)";
if (mysqli_query($con,$sql)){
echo "Table hoursByDay created successfully.<br>";
}
else{
echo "Error creating table: " . mysqli_error($con) . "<br>";
}
// Populate hoursByDay with initial data
$sql="load data local infile './TutorPreferences.txt' into table hoursByDay
fields terminated by ','";
if (mysqli_query($con,$sql)){
echo "hoursByDay loaded successfully.<br>";
}
else{
echo "Error loading data: " . mysqli_error($con) . "<br>";
}
// Drop openHours if previously there
$sql="drop table if exists openHours";
if(mysqli_query($con,$sql)){
echo "Deleted previously existing openHours table <br>";
}
// Create openHours
$sql="create table openHours (
day VARCHAR(15),
h07 INT, h08 INT, h09 INT, h10 INT, h11 INT, h12 INT, h13 INT, h14 INT,
h15 INT, h16 INT, h17 INT, h18 INT, h19 INT, h20 INT, h21 INT, h22 INT,
h23 INT)";
if (mysqli_query($con,$sql)){
echo "Table openHours created successfully.<br>";
}
else{
echo "Error creating table: " . mysqli_error($con) . "<br>";
}
// Populate openHours with initial data (all open)
$sql="load data local infile './testHours.txt' into table openHours
fields terminated by ','";
if (mysqli_query($con,$sql)){
echo "openHours loaded successfully.<br>";
}
else{
echo "Error loading data: " . mysqli_error($con) . "<br>";
}
// Drop actSchedule if previously there
$sql="drop table if exists actSchedule";
if(mysqli_query($con,$sql)){
echo "Deleted previously existing actSchedule table <br>";
}
// Create actSchedule
$sql="create table actSchedule (
PID INT NOT NULL AUTO_INCREMENT,
PRIMARY KEY (PID,day),
day VARCHAR(15),
h00 INT, h01 INT, h02 INT, h03 INT, h04 INT, h05 INT, h06 INT, h07 INT,
h08 INT, h09 INT, h10 INT, h11 INT, h12 INT, h13 INT, h14 INT, h15 INT,
h16 INT, h17 INT, h18 INT, h19 INT, h20 INT, h21 INT, h22 INT, h23 INT)";
if (mysqli_query($con,$sql)){
echo "Table actSchedule created successfully.<br>";
}
else{
echo "Error creating table: " . mysqli_error($con) . "<br>";
}
// // Populate actSchedule with initial data
// $sql="load data local infile './testMaster.txt' into table actSchedule
// fields terminated by ','";
// if (mysqli_query($con,$sql)){
// echo "actSchedule loaded successfully.<br>";
// }
// else{
// echo "Error loading data: " . mysqli_error($con) . "<br>";
// }
// Drop tutorComments if previously there
$sql="drop table if exists tutorComments";
if(mysqli_query($con,$sql)){
echo "Deleted previously existing tutorComments table <br>";
}
// Create tutorComments
$sql="create table tutorComments (
PID INT NOT NULL AUTO_INCREMENT,
PRIMARY KEY (PID),
comments TEXT(2000))";
if (mysqli_query($con,$sql)){
echo "Table tutorComments created successfully.<br>";
}
else{
echo "Error creating table: " . mysqli_error($con) . "<br>";
}
// Populate tutorComments with initial data
$sql="load data local infile './testComments.txt' into table tutorComments
fields terminated by ','";
if (mysqli_query($con,$sql)){
echo "tutorComments loaded successfully.<br>";
}
else{
echo "Error loading data: " . mysqli_error($con) . "<br>";
}
// Drop uGradWeeklyHours if previously there
$sql="drop table if exists uGradWeeklyHours";
if(mysqli_query($con,$sql)){
echo "Deleted previously existing uGradWeeklyHours table <br>";
}
// Create uGradWeeklyHours
$sql="create table uGradWeeklyHours (
PID INT NOT NULL AUTO_INCREMENT,
PRIMARY KEY (PID),
minHours INT, maxHours INT, idealHours INT)";
if (mysqli_query($con,$sql)){
echo "Table uGradWeeklyHours created successfully.<br>";
}
else{
echo "Error creating table: " . mysqli_error($con) . "<br>";
}
// Populate uGradWeeklyHours with initial data
$sql="load data local infile './testWeekHours.txt' into table uGradWeeklyHours
fields terminated by ','";
if (mysqli_query($con,$sql)){
echo "uGradWeeklyHours loaded successfully.<br>";
}
else{
echo "Error loading data: " . mysqli_error($con) . "<br>";
}
// Drop maxDayHours if previously there
$sql="drop table if exists maxDayHours";
if(mysqli_query($con,$sql)){
echo "Deleted previously existing maxDayHours table <br>";
}
// Create maxDayHours
$sql="create table maxDayHours (
PID INT NOT NULL AUTO_INCREMENT,
PRIMARY KEY (PID),
dayHours INT)";
if (mysqli_query($con,$sql)){
echo "Table maxDayHours created successfully.<br>";
}
else{
echo "Error creating table: " . mysqli_error($con) . "<br>";
}
// Populate maxDayHours with initial data
$sql="load data local infile './testDayHours.txt' into table maxDayHours
fields terminated by ','";
if (mysqli_query($con,$sql)){
echo "maxDayHours loaded successfully.<br>";
}
else{
echo "Error loading data: " . mysqli_error($con) . "<br>";
}
mysqli_close($con);
?>