-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.php
85 lines (48 loc) · 1.99 KB
/
functions.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
<?php
/**
* Created by PhpStorm.
* User: root
* Date: 10/26/15
* Time: 10:37 PM
*/
namespace apiClass;
include 'DbHandler.php';
class DbEntry{
public function registerUser($username, $password){
$db_handler = new DbHandler(HOSTNAME, USERNAME, PASSWORD);
$db_handler->selectDatabase(DBNAME);
$query = "INSERT INTO users (username, password, created_at, modified_at)
VALUES ('$username', sha1('$password'), NOW(), NOW())";
$result = $db_handler ->query($query);
return $result;
}
public function insertHouses($user_id, $house_name, $location, $house_color){
$db_handler = new DbHandler(HOSTNAME, USERNAME, PASSWORD);
$db_handler->selectDatabase(DBNAME);
$query = "INSERT INTO houses (user_id, house_name, house_location, house_color,
created_at, modified_at) VALUES('$user_id', '$$house_name', '$location', '$house_color',
NOW(), NOW())";
$result = $db_handler ->query($query);
return $result;
}
public function getUserIdByName($user){
$db_handler = new DbHandler(HOSTNAME, USERNAME, PASSWORD);
$db_handler->selectDatabase(DBNAME);
$query = "SELECT user_id FROM users WHERE username ='$user' AND active_status = 1";
$result = mysql_fetch_assoc($db_handler ->query($query));
return $result['user_id'];
}
public function getHousesByUserId($userId){
$db_handler = new DbHandler(HOSTNAME, USERNAME, PASSWORD);
$db_handler->selectDatabase(DBNAME);
$query = "SELECT DISTINCT houses.user_id, houses.house_id, houses.house_name,
houses.house_location, houses.house_color FROM houses INNER JOIN users
WHERE houses.user_id ='$userId' ";
$result = ($db_handler ->query($query));
$getResult = array();
while ($row = mysql_fetch_assoc($result)) {
$getResult[] = $row;
}
return $getResult;
}
}