forked from kalyanm72/Online-Bus-Booking
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Post_route.php
199 lines (172 loc) · 6.87 KB
/
Post_route.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
198
199
<?php
class Post_route{
private $conn;
private $table='route';
public $rid;
public $bid;
public $fromLoc;
public $toLoc;
public $fare;
public $dep_time;
public $dep_date;
public $arr_time;
public $arr_date;
public $avalseats;
public $maxseats;
public function __construct($db){
$this->conn=$db;
}
public function read(){
$query='SELECT p.rid,p.bid,p.fromLoc,p.toLoc,p.fare,p.dep_date,p.dep_time,p.arr_date,p.arr_time,p.avalseats,p.maxseats
FROM ' .$this->table. ' p ';
$stmt=$this->conn->prepare($query);
$stmt->execute();
return $stmt;
}
public function read_single(){
$query='SELECT b.type_sl as type_sl,b.type_ac as type_ac,b.bname as bname,b.bid as bid ,p.rid,p.bid,p.fromLoc,p.toLoc,p.fare,p.dep_date,p.dep_time,p.arr_date,p.arr_time,p.avalseats,p.maxseats
FROM ' .$this->table. ' p
LEFT JOIN
bus b ON p.bid = b.bid
WHERE p.fromLoc= ? AND p.toLoc= ? AND p.dep_date= ?
';
$stmt=$this->conn->prepare($query);
$stmt->bindParam(1,$this->fromLoc);
$stmt->bindParam(2,$this->toLoc);
$stmt->bindParam(3,$this->dep_date);
$stmt->execute();
return $stmt;
$row=$stmt->fetch(PDO::FETCH_ASSOC);
$this->rid=$row['rid'];
$this->bname=$row['bname'];
$this->fare=$row['fare'];
$this->dep_time=$row['dep_time'];
$this->arr_time=$row['arr_time'];
$this->arr_date=$row['arr_date'];
$this->avalseats=$row['avalseats'];
$this->type_ac=$row['type_ac'];
$this->type_sl=$row['type_sl'];
}
public function read_single_r(){
$query='SELECT b.type_sl as type_sl,b.type_ac as type_ac,b.bname as bname,b.bid as bid ,p.rid,p.bid,p.fromLoc,p.toLoc,p.fare,p.dep_date,p.dep_time,p.arr_date,p.arr_time,p.avalseats,p.maxseats
FROM ' .$this->table. ' p
LEFT JOIN
bus b ON p.bid = b.bid
WHERE p.rid= ?
';
$stmt=$this->conn->prepare($query);
$stmt->bindParam(1,$this->rid);
$stmt->execute();
return $stmt;
$row=$stmt->fetch(PDO::FETCH_ASSOC);
$this->rid=$row['rid'];
$this->bname=$row['bname'];
$this->fromLoc=$row['fromLoc'];
$this->fare=$row['fare'];
$this->dep_date=$row['dep_date'];
$this->toLoc=$row['toLoc'];
$this->dep_time=$row['dep_time'];
$this->arr_time=$row['arr_time'];
$this->arr_date=$row['arr_date'];
$this->avalseats=$row['avalseats'];
$this->type_ac=$row['type_ac'];
$this->type_sl=$row['type_sl'];
}
public function create() {
// Create query
$query = 'INSERT INTO ' . $this->table . '
SET
bid = :bid,
fromLoc = :fromLoc,
toLoc = :toLoc,
fare = :fare,
dep_date = :dep_date,
dep_time = :dep_time,
arr_time = :arr_time,
arr_date = :arr_date, avalseats = :avalseats, maxseats = :maxseats';
// Prepare statement
$stmt = $this->conn->prepare($query);
// Clean data
$this->bid=htmlspecialchars(strip_tags($this->bid));
$this->fromLoc=htmlspecialchars(strip_tags($this->fromLoc));
$this->toLoc=htmlspecialchars(strip_tags($this->toLoc));
$this->fare=htmlspecialchars(strip_tags($this->fare));
$this->dep_date=htmlspecialchars(strip_tags($this->dep_date));
$this->dep_time=htmlspecialchars(strip_tags($this->dep_time));
$this->arr_time=htmlspecialchars(strip_tags($this->arr_time));
$this->arr_date=htmlspecialchars(strip_tags($this->arr_date));
$this->avalseats=htmlspecialchars(strip_tags($this->avalseats));
$this->maxseats=htmlspecialchars(strip_tags($this->maxseats));
// Bind data
$stmt->bindParam(':bid', $this->bid);
$stmt->bindParam(':fromLoc', $this->fromLoc);
$stmt->bindParam(':toLoc', $this->toLoc);
$stmt->bindParam(':fare', $this->fare);
$stmt->bindParam(':dep_date', $this->dep_date);
$stmt->bindParam(':dep_time', $this->dep_time);
$stmt->bindParam(':arr_date', $this->arr_date);
$stmt->bindParam(':arr_time', $this->arr_time);
$stmt->bindParam(':avalseats', $this->avalseats);
$stmt->bindParam(':maxseats', $this->maxseats);
// Execute query
if($stmt->execute()) {
return true;
}
}
public function update() {
// Create query
$query = 'UPDATE ' . $this->table . '
SET
bid = :bid,
fromLoc = :fromLoc,
toLoc = :toLoc,
fare = :fare,
dep_date = :dep_date,
dep_time = :dep_time,
arr_time = :arr_time,
arr_date = :arr_date, avalseats = :avalseats, maxseats = :maxseats
WHERE
rid=:rid
';
// Prepare statement
$stmt = $this->conn->prepare($query);
// Clean data
$this->rid=htmlspecialchars(strip_tags($this->rid));
$this->bid=htmlspecialchars(strip_tags($this->bid));
$this->fromLoc=htmlspecialchars(strip_tags($this->fromLoc));
$this->toLoc=htmlspecialchars(strip_tags($this->toLoc));
$this->fare=htmlspecialchars(strip_tags($this->fare));
$this->dep_date=htmlspecialchars(strip_tags($this->dep_date));
$this->dep_time=htmlspecialchars(strip_tags($this->dep_time));
$this->arr_time=htmlspecialchars(strip_tags($this->arr_time));
$this->arr_date=htmlspecialchars(strip_tags($this->arr_date));
$this->avalseats=htmlspecialchars(strip_tags($this->avalseats));
$this->maxseats=htmlspecialchars(strip_tags($this->maxseats));
// Bind data
$stmt->bindParam(':rid', $this->rid);
$stmt->bindParam(':bid', $this->bid);
$stmt->bindParam(':fromLoc', $this->fromLoc);
$stmt->bindParam(':toLoc', $this->toLoc);
$stmt->bindParam(':fare', $this->fare);
$stmt->bindParam(':dep_date', $this->dep_date);
$stmt->bindParam(':dep_time', $this->dep_time);
$stmt->bindParam(':arr_date', $this->arr_date);
$stmt->bindParam(':arr_time', $this->arr_time);
$stmt->bindParam(':avalseats', $this->avalseats);
$stmt->bindParam(':maxseats', $this->maxseats);
// Execute query
if($stmt->execute()) {
return true;
}
}
public function delete(){
$query='DELETE FROM ' . $this->table . ' WHERE rid=:rid';
$stmt = $this->conn->prepare($query);
// Clean data
$this->rid=htmlspecialchars(strip_tags($this->rid));
$stmt->bindParam(':rid', $this->rid);
if($stmt->execute()) {
return true;
}
}
}