CodeIgniter
/application/models/active_record.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 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); class Active_record extends CI_Model { function __construct() { parent::__construct(); } public function msr($table,$field,$sb){ $this->db->order_by($field,$sb); return $this->db->get($table); } public function msrgp($table,$field,$sb,$gb){ $this->db->group_by($gb); $this->db->order_by($field,$sb); return $this->db->get($table); } public function msrpag($table,$field,$sb,$limit,$offset){ $this->db->order_by($field,$sb); $this->db->limit($limit, $offset); return $this->db->get($table); } public function msrwhere($table,$com,$field,$sb){ $this->db->order_by($field,$sb); return $this->db->get_where($table, $com); } public function msrwherelimit($table,$com,$field,$sb){ $this->db->order_by($field,$sb); $this->db->limit(5); return $this->db->get_where($table, $com); } public function msrwherelimitspec($table,$com,$field,$sb,$lim){ $this->db->order_by($field,$sb); $this->db->limit($lim); return $this->db->get_where($table, $com); } public function msrwhere_select($table,$com,$field,$sb,$select){ $this->db->select($select); $this->db->order_by($field,$sb); $this->db->limit(5); return $this->db->get_where($table, $com); } public function msrwhere_select_group($table,$field,$sb,$select,$field2, $names){ $this->db->select($select); $this->db->group_by($select); $this->db->order_by($field,$sb); $this->db->where_in($field2, $names); return $this->db->get($table); } public function msrwhereJoin2Table($table1,$table2,$com,$com2,$id,$field,$sb,$select){ $this->db->select($select); $this->db->from($table1); $this->db->order_by($field,$sb); $this->db->join($table2, $com); $this->db->where($com2, $id); return $this->db->get(); } public function msrwhereJoin3Table($table1,$table2,$table3,$com1,$com2,$field,$field2,$sb,$select,$com3,$id){ $this->db->select($select); $this->db->from($table1); $this->db->join($table2, $com1); $this->db->join($table3, $com2); $this->db->order_by($field,$sb); $this->db->order_by($field2,$sb); $this->db->where($com3, $id); return $this->db->get(); } public function msrwheregp($select,$table,$com,$field,$sb){ $this->db->select($select); $this->db->group_by($select); $this->db->order_by($field,$sb); return $this->db->get_where($table, $com); } public function msrwherepag($table,$com,$field,$sb,$limit,$offset){ $this->db->order_by($field,$sb); return $this->db->get_where($table, $com, $limit, $offset); } public function msrwherepaggr($table,$com,$limit,$offset,$gb){ $this->db->group_by($gb); return $this->db->get_where($table, $com, $limit, $offset); } function save($table, $set){ $this->db->insert($table, $set); return $this->db->insert_id(); } function edit($table, $set,$field, $id){ $this->db->where($field, $id); $this->db->update($table, $set); } function delete($table,$field,$id){ $this->db->delete($table, array($field => $id)); } function msrseek($keyword,$table,$field){ $this->db->select('*')->from($table); $this->db->like($field,strtoupper($keyword),'after'); $query = $this->db->get(); return $query; } function msrseek2($keyword,$table,$field,$com){ $this->db->select('*')->from($table); $this->db->where($com); $this->db->like($field,$keyword,'after'); $query = $this->db->get(); return $query; } function msrquery($sql){ $query = $this->db->query($sql); return $query; } function seekLookup($keyword,$table,$field,$short,$data,$name){ $this->db->select('*'); $this->db->like($name,$keyword); $this->db->order_by($field,$short); $this->db->limit(10); return $this->db->get_where($table,$data); } function seekLookup2($keyword,$table,$field,$short,$data,$name,$field2,$names){ $this->db->select('*'); $this->db->like($name,$keyword); $this->db->order_by($field,$short); $this->db->limit(10); $this->db->where_in($field2, $names); return $this->db->get_where($table,$data); } function seek($keyword,$table,$field,$data){ $this->db->like($field,$keyword,'after'); $query = $this->db->get_where($table,$data); return $query; } function seek2($keyword,$table,$field,$short,$data,$num,$offset){ $this->db->like($field,$keyword,'after'); $this->db->order_by($field,$short); $this->db->limit($num,$offset); $query = $this->db->get_where($table,$data); return $query; } public function msrNot($table,$field,$sb,$field2, $names){ $this->db->order_by($field,$sb); $this->db->where_not_in($field2, $names); return $this->db->get($table); } public function msrNot2($table,$field,$sb,$field2, $names,$data){ $this->db->order_by($field,$sb); $this->db->where_not_in($field2, $names); return $this->db->get_where($table,$data); } public function msrIn($table,$field,$sb,$field2, $names,$data){ $this->db->order_by($field,$sb); $this->db->where_in($field2, $names); return $this->db->get_where($table,$data); } function msrIngb($select,$table,$field,$short,$data,$field2,$names){ $this->db->select($select); $this->db->order_by($field,$short); $this->db->group_by($select); $this->db->where_in($field2, $names); return $this->db->get_where($table,$data); } public function msrmax($table,$field,$com){ $this->db->select_max($field,'maxi'); return $this->db->get_where($table,$com); } } |