-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpdoClass.php
74 lines (54 loc) · 2.21 KB
/
pdoClass.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
<?php
include_once('credentials.php');
class Mover{
protected $db;
public function __construct(){ // init the pdo
$this->db = new PDO('mysql:host='.HOST.';dbname='.DBNAME.';charset=utf8',
USR, PWD);
}
// This function puts a club into "clubs"
public function moveClubs($clubId, $clubName, $city, $county)
{
$sql = "INSERT INTO clubs (clubId, clubName, city, county)
VALUES (:clubId, :clubName, :city, :county)"; // sql statment
$stmt = $this->db->prepare($sql); // binding values
$stmt->bindValue(':clubId', $clubId);
$stmt->bindValue(':clubName', $clubName);
$stmt->bindValue(':city', $city);
$stmt->bindValue(':county', $county);
$afNo = $stmt->execute();
}
// This function puts a skier in "skiers"
public function moveSkiers($userName, $fName, $lName, $bYear, $clubId)
{
$sql = "INSERT INTO skiers (userName, fName, lName, bYear, clubId)
VALUES (:userName, :fName, :lName, :bYear, :clubId)"; // sql statment
$stmt = $this->db->prepare($sql); // binding values
$stmt->bindValue(':userName', $userName);
$stmt->bindValue(':fName', $fName);
$stmt->bindValue(':lName', $lName);
$stmt->bindValue(':bYear', $bYear);
if($clubId != NULL){$stmt->bindValue(':clubId', $clubId);} // if part of club
else{$stmt->bindValue(':clubId', NULL);} // not part of club
$afNo = $stmt->execute();
}
// This function gets the fallYear and moves to table"season"
public function moveSeasons($fallYear){
$sql = "INSERT INTO season(fallYear) VALUES(:fallYear)"; // sql stamement
$stmt = $this->db->prepare($sql);
$stmt->bindValue(':fallYear', $fallYear); // bind to fallYear
$afNo = $stmt->execute();
}
// This function gets the fallYear, userName and totalDistance
// and moves to table "log"
public function moveDistance($userName, $fallYear, $totalDistance){
$sql = "INSERT INTO log(userName_fk, fallYear_fk, totalDistance)
VALUES(:userName, :fallYear, :totalDistance)"; // sql stamement
$stmt = $this->db->prepare($sql);
$stmt->bindValue(':userName', $userName); // bind to fallYear
$stmt->bindValue(':fallYear', $fallYear);
$stmt->bindValue(':totalDistance', $totalDistance);
$afNo = $stmt->execute();
}
}
?>