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.