_php example of common function encapsulation instance of CI framework

Source: Internet
Author: User

The examples in this article describe the common function encapsulation of the CI framework. Share to everyone for your reference, specific as follows:

/** * Package 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; /** * Encapsulates a single query function */Public function get_row ($table = ', $where =array (), $fields = ' * ') {if (' = = $table ') {retur
    n false;
    //query and return related results $query = $this->db->select ($fields)->where ($where)->get ($table);
    $res = $query->row_array ();
return $res;  /** * PACKAGE 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;
/** * Expansion of the database function from self reduction * 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)) {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; /** * Encapsulation 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 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 the controller: \ r \ n";
      $error. = $func. "Method debugging 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 the site topics: "CodeIgniter Introductory Course", "CI (CodeIgniter) Framework Advanced Course", "PHP Excellent Development Framework Summary", "thinkphp Introductory Course", " Thinkphp Common Methods Summary, "Zend Framework Introduction Course", "PHP object-oriented Programming Introduction Course", "Php+mysql Database operation Introduction Tutorial" and "PHP common database Operation Skills Summary"

I hope this article will help you with 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.