CI Framework common function Encapsulation Instance _php instance

Source: Internet
Author: User
Tags codeigniter zend framework
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.

  • 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.