-
Notifications
You must be signed in to change notification settings - Fork 0
/
mysql_setup.php
65 lines (55 loc) · 2.07 KB
/
mysql_setup.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
<?php
/** SETUP **/
include('database_variables.php');
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT); // Extra Error Printing
$db = new mysqli($SERVER, $USERNAME, $PASSWORD, $DATABASE); //NOT CREATING NEW DB, does this just set it?
//start fresh documentary info table
$db->query("drop table if exists documentaryInfo;");
//create documentary info table
$db->query("create table documentaryInfo(
docID int not null unique auto_increment,
overview TEXT(10000) NOT NULL UNIQUE,
averageRating int,
year NOT NULL,
primary key(docID));");
//start fresh documentaryTitleYear
//tbh I dont totally understand why this table exists -- dont we have the year in the documentary info table?? should we include this?
$db->query("drop table if exists documentaryTitleYear;");
//create documentary info table
$db->query("create table documentaryTitleYear(
docID int,
year YEAR REFERENCES documentaryInfo(year),
PRIMARY KEY(docID),
FOREIGN KEY(docID) REFERENCES documentaryInfo(docID),
title VARCHAR(255) NOT NULL);");
/*
$row = 1; // starts with first row of csv file/ first question
if (($handle = fopen("us-corporate-env-updated.csv", "r")) !== FALSE) { //make sure csv can open
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { //access csv contents
$num = count($data);
echo $num;
print_r($data);
//$row++;
$stmt = $db->prepare("insert into corporation (name, industry, cost) values (?,?,?);");
for ($c=0; $c < $num; $c++){
if ($c == 1){
$nameInsert = trim($data[$c]);
}
else if ($c == 2){
$industryInsert = trim($data[$c]);
}
else if ($c == 3){
$costInsert = trim($data[$c]);
}
}
$stmt->bind_param("sss", $nameInsert, $industryInsert, $costInsert);
if (!$stmt->execute()) {
echo "Could not add corporation: {$nameInsert}\n";
}
$row++;
}
}
fclose($handle);
*/
echo "Setup";
?>