Rev | Line | |
---|
[337] | 1 | <?php (defined('BASEPATH')) OR exit('No direct script access allowed');
|
---|
[327] | 2 |
|
---|
| 3 | class 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);
|
---|
[375] | 32 | $query = $this->db->get();
|
---|
[327] | 33 | if($query->num_rows() > 0)
|
---|
| 34 | {
|
---|
| 35 | $row = $query->row_array();
|
---|
[375] | 36 | return $row;
|
---|
[327] | 37 | }
|
---|
| 38 | }
|
---|
[337] | 39 |
|
---|
| 40 | function get_list()
|
---|
| 41 | {
|
---|
| 42 | $query = $this->db->get($this->table_name);
|
---|
| 43 | return $query->result();
|
---|
| 44 | }
|
---|
[375] | 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";
|
---|
[431] | 49 |
|
---|
| 50 | $result = $this->db->query($sql);
|
---|
| 51 | $aryResult = $result->row_array();
|
---|
| 52 | if (!isset($aryResult['total'])) return false;
|
---|
| 53 | if ((int)$aryResult['total'] >= 1) return true; else return false;
|
---|
[375] | 54 | }
|
---|
[327] | 55 | }
|
---|
Note: See
TracBrowser
for help on using the repository browser.