-
Notifications
You must be signed in to change notification settings - Fork 1
/
sportsData.php
89 lines (76 loc) · 2.08 KB
/
sportsData.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
<?php
require_once __DIR__ . "/database.php";
require_once __DIR__ . "/configVars.php";
$db = new Database(...$DB_CONFIG);
function createTable()
{
global $db;
$create_statement = "CREATE TABLE IF NOT EXISTS sports(
nameVal varchar(100),
sportName varchar(100) PRIMARY KEY,
startDate date,
endDate date,
venue varchar(100),
imgPath varchar(100)
)";
$registrationsCreate = "CREATE TABLE IF NOT EXISTS registraitions(
sport varchar(100),
user varchar(100),
PRIMARY KEY(sport,user)
)";
$db->fullExecute($create_statement);
$db->fullExecute($registrationsCreate);
}
function addData(array $data)
{
global $db;
$insert = "INSERT INTO sports(sportName,nameVal,startDate,endDate,venue,imgPath) VALUES(:sportName,:nameVal,:startDate,:endDate,:venue,:imgPath)";
$rs = $db->prepareAndReturn($insert);
$res = $rs->execute($data);
return $res;
}
function registerSport(string $sport, string $user)
{
global $db;
$data["sport"] = $sport;
$data["user"] = $user;
$insert = "INSERT INTO registraitions(sport,user) VALUES(:sport,:user)";
$rs = $db->prepareAndReturn($insert);
$res = $rs->execute($data);
return $res;
}
function findSport(string $sport)
{
global $db;
$find = "SELECT * from sports WHERE sportName='$sport'";
$rs = $db->fullFetch($find);
return $rs;
}
function findAllSport()
{
global $db;
$find = "SELECT * from sports";
$rs = $db->fullFetch($find);
return $rs;
}
function findByUser(string $user)
{
global $db;
$find = "SELECT * from registraitions WHERE user='$user'";
$rs = $db->fullFetch($find);
return $rs;
}
function findBySport(string $sport)
{
global $db;
$find = "SELECT * from registraitions WHERE sport='$sport'";
$rs = $db->fullFetch($find);
return $rs;
}
function findBySportAndUser(string $sport, string $user)
{
global $db;
$find = "SELECT * from registraitions WHERE sport='$sport' AND user='$user'";
$rs = $db->fullFetch($find);
return $rs;
}