-
Notifications
You must be signed in to change notification settings - Fork 1
/
database.php
44 lines (37 loc) · 966 Bytes
/
database.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
<?php
require_once("include/config.php");
require_once("models/Route.php");
$conn = new mysqli($hostname, $username, $password, $database);
if ($conn->connect_error)
{
fatalError($conn->connect_error);
return;
}
function getAllRoutes($conn)
{
$results = array();
$other_query = "SELECT routes.route_id, routes.route_short_name, routes.route_long_name
FROM akl_transport.routes";
//sanitize the query
mysqlCleaner($other_query);
$dbresult = $conn->query($other_query);
if (!$dbresult)
{
fatalError($conn->error);
}
else {
while ($row = $dbresult->fetch_array(MYSQLI_ASSOC))
{
$route = new Route($row['route_short_name'] . ' ' . $row['route_long_name'], $row['route_id']);
$results[] = $route;
}
$dbresult->close();
}
return $results;
}
function mysqlCleaner($data)
{
$data= stripslashes($data);
return $data;
}
?>