-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUser_model.php
More file actions
70 lines (63 loc) · 1.53 KB
/
User_model.php
File metadata and controls
70 lines (63 loc) · 1.53 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
61
62
63
64
65
66
67
68
69
70
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
/**
* Class User_model.
*
* Model to help interact with users table in database.
*/
class User_model extends CI_Model
{
/**
* @var string
*/
private $table;
/**
* User_model constructor.
*/
function __construct()
{
parent::__construct();
$this->table = 'users';
}
/**
* Retrieve the user details from the database table based on the given email and password.
*
* @param $email
* @param $password
* @return array
*/
function get_user($email, $password)
{
$this->db->where('email', $email);
$this->db->where('password', md5($password));
$query = $this->db->get($this->table);
return $query->result();
}
/**
* Retrieve the user details from the database table based on the given id of the user.
*
* @param $id
* @return array
*/
function get_user_by_id($id)
{
$this->db->where('id', $id);
$query = $this->db->get($this->table);
return $query->result();
}
/**
* Store the user information in the database table as is.
*
* @param $data
* @return int
*/
function save_user($data)
{
$insertFlag = $this->db->insert($this->table, $data);
if ($insertFlag) {
return $this->db->insert_id();
}
else {
return 0;
}
}
}