source: pro-violet-viettel/sourcecode/application/core/MY_Model.php @ 375

Last change on this file since 375 was 375, checked in by namnd, 11 years ago
File size: 1.2 KB
Line 
1<?php (defined('BASEPATH')) OR exit('No direct script access allowed');
2
3class MY_model extends CI_Model
4{
5        protected $table_name = '';
6        protected $id_name = '';
7       
8        function __construct()
9        {
10                parent::__construct();
11        }
12       
13        function insert($data)
14        {
15                return $this->db->insert($this->table_name, $data);
16        }
17       
18        function update($id, $data)
19        {
20                $this->db->where($this->id_name, $id);
21                return $this->db->update($this->table_name, $data);
22        }
23       
24        function delete($id)
25        {
26                return $this->db->delete($this->table_name, array($this->id_name => $id));
27        }
28       
29        function search_by_id($id)
30        {
31                $this->db->select('*')->from($this->table_name)->where($this->id_name, $id);
32                $query = $this->db->get();
33                if($query->num_rows() > 0)
34                {
35                        $row = $query->row_array();
36                        return $row;
37                }
38        }
39       
40        function get_list()
41        {
42                $query = $this->db->get($this->table_name);
43                return $query->result();
44        }
45       
46        function check_exist($data)
47        {
48                $sql="SELECT COUNT(".$this->id_name.") as total FROM ".$this->table_name." WHERE ".$data['field']." = '".$data['value']."' LIMIT 1";
49                if ($this->db->query($sql)->row_array()['total']==1)
50                {
51                        return true;
52                }
53                else
54                {
55                        return false;
56                }
57        }
58}
Note: See TracBrowser for help on using the repository browser.