-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_tables.php
executable file
·117 lines (95 loc) · 3.52 KB
/
create_tables.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
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
#!/bin/php
<?php
try {
require __DIR__ . "/include/mysql.php";
$db = new PDO("mysql:host=$servername;dbname=$dbname", $dbusername, $dbpassword);
// creating table for userLogin
$createUserTable = $db->prepare(
"CREATE TABLE IF NOT EXISTS `userLogin` (
`userID` int NOT NULL AUTO_INCREMENT,
`username` varchar(64) NOT NULL,
`password_hash` binary(32) NOT NULL, -- SHA-256 produces a 32-byte digest
`salt` binary(16) NOT NULL,
`email` varchar(255) NOT NULL,
PRIMARY KEY (`userID`),
UNIQUE KEY `username` (`username`)
) ENGINE=InnoDB DEFAULT CHARSET=ascii COLLATE=ascii_bin"
);
$createUserTable->execute(); // this will run the code above if it can
// end of creation of userLogins
// start of create of form table
$createFormTable = $db->prepare(
"CREATE TABLE IF NOT EXISTS formTable(
`userID` int not null,
`genre` varchar (100),
`duration` int not null,
`year` varchar (20),
`language` varchar (200),
Primary Key (`userID`),
Foreign Key (`userID`) references userLogin(`userID`)
);"
);
$createFormTable->execute();
// end of creation of form table
// creation of userSession
$createUserSes = $db->prepare(
"CREATE TABLE IF NOT EXISTS userSession(
`session_id` varchar (255),
`user_id` int not null,
`creation` int
);"
);
$createUserSes->execute(); // this will run the code above if it can
// end of isnta
//create of cachedMovie Table (for all movies :))
$cm = $db->prepare("CREATE TABLE IF NOT EXISTS `movies`(
`movie_id` int auto_increment,
`imdb_id` varchar (12) not null,
`title` varchar (200) not null,
`description` text,
`image` text,
`genre` varchar(200),
`duration` int (10),
`year` int (10),
`language` varchar (200),
Primary Key (movie_id)
);
");
$cm->execute(); // tnd of create cachedMovie
// start of userInventory
$ui = $db->prepare("CREATE TABLE IF NOT EXISTS `userInv`(
`movie_id` int not null,
`userID`int not null,
Foreign Key (`userID`) references userLogin(`userID`),
Foreign Key (`movie_id`) references movies(`movie_id`)
);");
$ui->execute(); // end of userInventory
// creating review table
$rc = $db->prepare("CREATE TABLE IF NOT EXISTS `reviews`(
`review_id` int auto_increment,
`movie_id` int not null,
`userID` int not null,
`reviewRating` int not null,
`reviewText` text,
Primary Key (review_id),
Foreign Key (`userID`) references userLogin(`userID`),
Foreign Key (`movie_id`) references movies(`movie_id`)
);
");
$rc->execute(); // end of userInventory
// -----------------------------------------------------
// creation of the table for followers
$createFollowTable = $db->prepare(
"CREATE TABLE IF NOT EXISTS `followTable`(
`fID` int auto_increment,
`followerID` int,
`followedID` int,
Primary Key (`fID`),
Foreign Key (`followerID`) references userLogin(`userID`),
Foreign Key (`followedID`) references userLogin(`userID`)
)"
);
$createFollowTable->execute();
} catch (Exception $e) {
echo $e->getMessage();
}