-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathapi.php
More file actions
60 lines (56 loc) · 1.13 KB
/
api.php
File metadata and controls
60 lines (56 loc) · 1.13 KB
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
<?php
/**
* API class
* @author Rob
* @version 2015-06-22
*/
class api
{
private $db;
/**
* Constructor - open DB connection
*
* @param none
* @return database
*/
function __construct()
{
$conf = json_decode(file_get_contents('configuration.json'), TRUE);
$this->db = new mysqli($conf["host"], $conf["user"], $conf["password"], $conf["database"]);
}
/**
* Destructor - close DB connection
*
* @param none
* @return none
*/
function __destruct()
{
$this->db->close();
}
/**
* Get the list of users
*
* @param none or user id
* @return list of data on JSON format
*/
function get($params)
{
$query = 'SELECT u.id AS id'
. ', u.username AS username'
. ', u.realname AS realname'
. ', u.password AS password'
. ', u.email AS email'
. ' FROM user AS u'
. ($params['id'] == ''? '' : ' WHERE u.id = \'' . $this->db->real_escape_string($params['id']) . '\'')
. ' ORDER BY u.username'
;
$list = array();
$result = $this->db->query($query);
while ($row = $result->fetch_assoc())
{
$list[] = $row;
}
return $list;
}
}