Examples of common CI framework function encapsulation and ci framework Encapsulation

Source: Internet
Author: User

Examples of common CI framework function encapsulation and ci framework Encapsulation

This example describes common function encapsulation in the CI framework. We will share this with you for your reference. The details are as follows:

/*** Encapsulate the query function */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 ;} /*** encapsulate a single query function */public function get_row ($ table = '', $ where = array (), $ fields = '*') {if (''= $ table) {return false;} // query and return related results $ query = $ this-> db-> select ($ field S)-> where ($ where)-> get ($ table); $ res = $ query-> row_array (); return $ res ;} /*** encapsulate the UPDATE function */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 ;} /*** auto-increment and auto-increment of extended database functions * using: * $ table = 'codeuser'; $ where = array ('id' => 1); $ data = ar Ray ('usestate' => 'usestate + 1', 'imgtype' => 'imgtype-1'); */public function update_count ($ table = '', $ where = array (), $ data = array ()) {// if the table name is null or the data is null, false is returned directly. if (''= $ table | empty ($ data) {return false ;} foreach ($ data as $ key => $ val) {if (false! = Stripos ($ val, '+') | false! = Stripos ($ val, '-') {$ this-> db-> set ($ key, $ val, FALSE );} else {$ this-> db-> set ($ key, $ val) ;}$ res = $ this-> db-> where ($ where) -> update ($ table); return $ res;}/*** encapsulate the insert function */public function insert_what ($ table = '', $ data = array ()) {if (''= $ table | true = empty ($ data) {return false ;} // insert related records $ query = $ this-> db-> insert ($ table, $ data); return $ query ;} /*** Delete record encapsulation function */public function 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 related functions */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. "\ r \ n" under the Controller; $ error. = $ func. "method debugging information: \ r \ n"; $ error. = $ org_error; file_put_contents (". /error_log.txt ", $ error. "\ r \ n", FILE_APPEND );}}

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.