About the common function encapsulation of CI framework

Source: Internet
Author: User
This article mainly introduced the CI framework commonly used function encapsulation, combined with the example form analysis of the CI framework commonly used database query, insert, delete, update and debug debugging and other operational skills, the need for friends can refer to the next

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); }}

The above is the whole content of this article, I hope that everyone's learning has helped, more relevant content please pay attention to topic.alibabacloud.com!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.