-
Notifications
You must be signed in to change notification settings - Fork 0
/
index_old.php
executable file
·67 lines (57 loc) · 1.75 KB
/
index_old.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
<?php
require 'Slim/Slim.php';
$app = new Slim();
$app->get('/questions', 'getQuestions');
$app->get('/tests', 'getTests');
$app->run();
function getQuestions() {
echo "Getting Questions";
$sql = "SELECT * from questions where flag='1'";
try {
$db = getConnection();
$stmt = $db->query($sql);
$projects = $stmt->fetchAll(PDO::FETCH_OBJ);
$db = null;
// Include support for JSONP requests
if (!isset($_GET['callback'])) {
echo json_encode($projects);
} else {
echo $_GET['callback'] . '(' . json_encode($projects) . ');';
}
} catch(PDOException $e) {
echo '{"error":{"text":'. $e->getMessage() .'}}';
}
}
function getTests(){
/*if (isset($_GET['name'])) {
return getEmployeesByName($_GET['name']);
} else if (isset($_GET['modifiedSince'])) {
return getModifiedEmployees($_GET['modifiedSince']);
}*/
$sql = "SELECT p.id as id,p.name AS name,p.address,p.lat,p.lng,p.min_rate,p.max_rate, p.area, p.logo, b.name AS builder_name
FROM projects p LEFT JOIN builders b ON p.builder_id=b.id";
try {
$db = getConnection();
$stmt = $db->query($sql);
$projects = $stmt->fetchAll(PDO::FETCH_OBJ);
$db = null;
// Include support for JSONP requests
if (!isset($_GET['callback'])) {
echo json_encode($projects);
} else {
echo $_GET['callback'] . '(' . json_encode($projects) . ');';
}
} catch(PDOException $e) {
echo '{"error":{"text":'. $e->getMessage() .'}}';
}
}
function getConnection() {
$dbhost="127.0.0.1";
$dbuser="root";
$dbpass="";
$dbname="edu";
$dbh = new PDO("mysql:host=$dbhost;dbname=$dbname", $dbuser, $dbpass);
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
return $dbh;
}
?>