The examples in this paper describe the common function encapsulation of CI framework. Share to everyone for your reference, as follows:
/*** Package Query functions */public function get_what ($table = ", $where =array (), $fields = ' * ') {if (' = = $table) {return false; }//Query and return related results $query = $this->db->select ($fields)->where ($where)->get ($table); $res = $query->result_array (); return $res;} /*** Package single query function */public function get_row ($table = ", $where =array (), $fields = ' * ') {if (' = = $table) {return false ; }//Query and return related results $query = $this->db->select ($fields)->where ($where)->get ($table); $res = $query->row_array (); return $res;} /*** Package Update functions */public function update_what ($table = ", $where =array (), $data = Array ()) {if (' = = $table | | true = = = Empty ($where) | | true = = = Empty ($data)) {return false; }//update the corresponding field $query = $this->db->update ($table, $data, $where); return $query;} /*** Extended database function self-increment * using:* $table = ' Codeuser '; $where = array (' ID ' =>1); $data = Array (' usestate ' = ' usestate+1 ', ' Imgtype ' = ' imgtype-1 '); */public function Update_count ($table = ", $where =array (), $data =array ()) {//If the table name is empty or the data is empty, return false if (' = = $table | | empty ($DATA)) {Retu RN false; } foreach ($data as $key = + $val) {if (False!== Stripos ($val, ' + ') | | false!== stripos ($val, '-') {$th Is->db->set ($key, $val, FALSE); }else{$this->db->set ($key, $val); }} $res = $this->db->where ($where)->update ($table); return $res;} /*** encapsulated Insert Function */public functions insert_what ($table = ', $data = Array ()) {if (' = = $table | | true = = = Empty ($data)) { return false; }//Insert related record $query = $this->db->insert ($table, $data); return $query;} /*** Delete Record encapsulation function */public functions delete_what ($table = ", $where =array ()) {if (true = = = Empty ($where) | | "= = $table) {return false; }//delete related table records $query = $this->db->delete ($table, $where); return $query;} /*** Debug Correlation function */Public Function debug_what ($org _error = ") {$con = $this->router->fetch_clasS (); $func = $this->router->fetch_method (); if ($org _error) {$error. = Date ("Y-m-d h:i:s", Time ()). " \ r \ n "; $error. = __file__. " \ r \ n "; $error. = $con. "Under controller: \ r \ n"; $error. = $func. "Method debug information is as follows: \ r \ n"; $error. = $org _error;file_put_contents ("./error_log.txt", $error. " \ r \ n ", file_append); }}
More interested in CodeIgniter related content readers can view this site topic: "CodeIgniter Introductory Tutorial", "CI (codeigniter) Framework Advanced Tutorial", "PHP Excellent Development Framework Summary", "thinkphp Getting Started", " Summary of common methods of thinkphp, "Introduction to Zend Framework Frame", "Introduction to PHP Object-oriented Programming", "Introduction to Php+mysql Database Operation" and "PHP common database Operation Skills Summary"
It is hoped that this article is helpful to the PHP program design based on CodeIgniter framework.