-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.php
62 lines (53 loc) · 1.59 KB
/
demo.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
<?php
/**
* Class to handle all db operations
* This class will have CRUD methods for database tables
*
* @author Ravi Tamada
* @link URL Tutorial link
*/
class Demo {
private $conn;
function __construct() {
require_once dirname(__FILE__) . '/include/db_connect.php';
// opening db connection
$db = new DbConnect();
$this->conn = $db->connect();
}
public function getAllChatRooms() {
$stmt = $this->conn->prepare("SELECT * FROM chat_rooms");
$stmt->execute();
$tasks = $stmt->get_result();
$stmt->close();
return $tasks;
}
public function getAllUsers() {
$stmt = $this->conn->prepare("SELECT * FROM users");
$stmt->execute();
$tasks = $stmt->get_result();
$stmt->close();
return $tasks;
}
public function getDemoUser() {
$name = 'AndroidHive';
$email = '[email protected]';
$stmt = $this->conn->prepare("SELECT user_id from users WHERE email = ?");
$stmt->bind_param("s", $email);
$stmt->execute();
$stmt->store_result();
$num_rows = $stmt->num_rows;
if ($num_rows > 0) {
$stmt->bind_result($user_id);
$stmt->fetch();
return $user_id;
} else {
$stmt = $this->conn->prepare("INSERT INTO users(name, email) values(?, ?)");
$stmt->bind_param("ss", $name, $email);
$result = $stmt->execute();
$user_id = $stmt->insert_id;
$stmt->close();
return $user_id;
}
}
}
?>