-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmysql.php
197 lines (172 loc) · 7.27 KB
/
mysql.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
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
<?php
$host = "localhost";
$user = "root";
$password = "";
$database = "lolrs201_esms";
$con = mysqli_connect($host, $user , $password);
if (!$con)
{die('Could not connect: ' . mysql_error());}
mysqli_query($con, "CREATE DATABASE IF NOT EXISTS `lolrs201_esms`");
mysqli_select_db($con, $database);
mysqli_query($con, "SET character_set_results=utf8");
mb_language('uni');
mb_internal_encoding('UTF-8');
mysqli_query($con, "set names 'utf8'");
mysqli_query($con, "CREATE TABLE IF NOT EXISTS `esms_users`(
`userID` bigint(12) NOT NULL AUTO_INCREMENT ,
`username` varchar(80) NOT NULL,
`password` varchar(80) NOT NULL,
`email` varchar(80) NOT NULL,
`level` int(2) NOT NULL DEFAULT 1,
`code` varchar(80) NOT NULL,
`active` int(1) NOT NULL,
`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
`updated_at` TIMESTAMP,
`remember_token` varchar(100) NULL,
PRIMARY KEY(`userID`),
UNIQUE(`username`,`email`)
)
DEFAULT CHARACTER SET = utf8
");
mysqli_query($con, "CREATE TABLE IF NOT EXISTS `esms_teams` (
`teamID` bigint(12) NOT NULL AUTO_INCREMENT,
`tag` varchar(30) NOT NULL,
`name` varchar(60) NOT NULL,
`captain` bigint(12) NOT NULL,
`facebook` varchar(80) NULL,
`twitter` varchar(80) NULL,
`website` varchar(80) NULL,
`about` text NULL,
`avatar` varchar(255) NULL,
`country` varchar(255) NULL,
`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
`updated_at` TIMESTAMP,
PRIMARY KEY (`teamID`),
UNIQUE(`name`,`tag`)
)
DEFAULT CHARACTER SET = utf8
");
mysqli_query($con, "CREATE TABLE IF NOT EXISTS `esms_players`(
`playerID` bigint(12) NOT NULL AUTO_INCREMENT,
`userID` bigint(12) NOT NULL,
`name` varchar(60) NULL,
`last_name` varchar(60) NULL,
`nick` varchar(100) NULL,
`teamID` bigint(12) NULL,
`avatar` varchar(255) NULL,
`position` varchar(255) NULL,
`bio` text NULL,
`country` varchar(255) NULL,
`facebook` varchar(80) NULL,
`twitter` varchar(80) NULL,
`website` varchar(80) NULL,
`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
`updated_at` TIMESTAMP,
PRIMARY KEY(`playerID`),
FOREIGN KEY(`userID`) REFERENCES esms_users(userID) ON DELETE CASCADE ON UPDATE CASCADE,
FOREIGN KEY(`teamID`) REFERENCES esms_teams(teamID) ON DELETE SET NULL ON UPDATE CASCADE
)
DEFAULT CHARACTER SET = utf8
");
// mysqli_query($con, "ALTER TABLE `esms_teams` ADD FOREIGN KEY (`captain`) REFERENCES esms_players(playerID) ");
mysqli_query($con, "CREATE TABLE IF NOT EXISTS `esms_tournaments` (
`tournamentID` bigint(12) NOT NULL AUTO_INCREMENT,
`starting` TIMESTAMP NULL,
`max_teams` int(5) NULL,
`name` varchar(255) NULL,
`prizepool` varchar(255) NULL,
`reg_open` int(1) NULL,
`type` varchar(30) NOT NULL,
`cover` varchar(255) NULL,
`winnerID` bigint(12) NULL,
`second_place` bigint(12) NULL,
`third_place` bigint(12) NULL,
`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
`updated_at` TIMESTAMP,
PRIMARY KEY(`tournamentID`),
FOREIGN KEY(`winnerID`) REFERENCES esms_teams(teamID) ON DELETE NO ACTION ON UPDATE CASCADE,
FOREIGN KEY(`second_place`) REFERENCES esms_teams(teamID) ON DELETE NO ACTION ON UPDATE CASCADE,
FOREIGN KEY(`third_place`) REFERENCES esms_teams(teamID) ON DELETE NO ACTION ON UPDATE CASCADE
)
DEFAULT CHARACTER SET = utf8
");
mysqli_query($con, "CREATE TABLE IF NOT EXISTS `esms_matches` (
`matchID` bigint(12) NOT NULL AUTO_INCREMENT,
`host` bigint(12) NULL,
`guest` bigint(12) NULL,
`winnerID` bigint(12) NULL,
`time` TIMESTAMP NULL,
`tournamentID` bigint(12) NOT NULL,
`tournament_phase` varchar(60) NULL,
`child_match_a` bigint(12) NULL,
`child_match_b` bigint(12) NULL,
`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
`updated_at` TIMESTAMP,
PRIMARY KEY(`matchID`),
FOREIGN KEY(`host`) REFERENCES esms_teams(teamID) ON DELETE NO ACTION ON UPDATE CASCADE,
FOREIGN KEY(`guest`) REFERENCES esms_teams(teamID) ON DELETE NO ACTION ON UPDATE CASCADE,
FOREIGN KEY(`tournamentID`) REFERENCES esms_tournaments(tournamentID) ON DELETE CASCADE ON UPDATE CASCADE
)
DEFAULT CHARACTER SET = utf8
");
mysqli_query($con, "CREATE TABLE IF NOT EXISTS `esms_player_scores` (
`locID` bigint(12) NOT NULL AUTO_INCREMENT,
`tournamentID` bigint(12) NOT NULL,
`matchID` bigint(12) NOT NULL,
`playerID` bigint(12) NOT NULL,
`k` int(5) NULL DEFAULT 0,
`d` int(5) NULL DEFAULT 0,
`a` int(5) NULL DEFAULT 0,
`cs` int(5) NULL DEFAULT 0,
`entity` varchar(30) NULL,
`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
`updated_at` TIMESTAMP,
PRIMARY KEY(`locID`),
FOREIGN KEY(`tournamentID`) REFERENCES esms_tournaments(tournamentID) ON DELETE CASCADE ON UPDATE CASCADE,
FOREIGN KEY(`matchID`) REFERENCES esms_matches(matchID) ON DELETE NO ACTION ON UPDATE CASCADE,
FOREIGN KEY(`playerID`) REFERENCES esms_players(playerID) ON DELETE CASCADE ON UPDATE CASCADE
)
DEFAULT CHARACTER SET = utf8
");
mysqli_query($con, "CREATE TABLE IF NOT EXISTS `esms_player_invites` (
`locID` bigint(12) NOT NULL AUTO_INCREMENT,
`inviter` bigint(12) NOT NULL,
`invited` bigint(12) NOT NULL,
`team` bigint(12) NOT NULL,
`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
`updated_at` TIMESTAMP,
PRIMARY KEY(`locID`),
FOREIGN KEY(`inviter`) REFERENCES esms_players(playerID) ON DELETE CASCADE ON UPDATE CASCADE,
FOREIGN KEY(`invited`) REFERENCES esms_players(playerID) ON DELETE CASCADE ON UPDATE CASCADE,
FOREIGN KEY(`team`) REFERENCES esms_teams(teamID) ON DELETE CASCADE ON UPDATE CASCADE
)
DEFAULT CHARACTER SET = utf8
");
mysqli_query($con, "CREATE TABLE IF NOT EXISTS `esms_tour_applies` (
`locID` bigint(12) NOT NULL AUTO_INCREMENT,
`tournament` bigint(12) NOT NULL,
`team` bigint(12) NOT NULL,
`played` int(5) NULL DEFAULT 0,
`won` int(5) NULL DEFAULT 0,
`lost` int(5) NULL DEFAULT 0,
`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
`updated_at` TIMESTAMP,
PRIMARY KEY(`locID`),
FOREIGN KEY(`tournament`) REFERENCES esms_tournaments(tournamentID) ON DELETE CASCADE ON UPDATE CASCADE,
FOREIGN KEY(`team`) REFERENCES esms_teams(teamID) ON DELETE CASCADE ON UPDATE CASCADE
)
DEFAULT CHARACTER SET = utf8
");
/*mysqli_query($con, "CREATE TABLE IF NOT EXISTS `esms_brackets` (
`locID` bigint(12) NOT NULL AUTO_INCREMENT,
`tournament` bigint(12) NOT NULL,
`matchID` bigint(12) NOT NULL,
`childID1` bigint(12) NULL,
`childID2` bigint(12) NULL,
`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
`updated_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY(`locID`),
FOREIGN KEY(`matchID`) REFERENCES esms_matches(matchID) ON DELETE CASCADE ON UPDATE CASCADE
)
DEFAULT CHARACTER SET = utf8
");*/