Get the App
SLTechnology News&Howtos  ›  Development  › 

Encapsulation of common functions in CI framework

Shulou Source: shulou.com Published: 2022-06-03 19:16:48 09月15日 Update

This article mainly shows you the "CI framework common function encapsulation", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn the "CI framework common function encapsulation" this article.

The details are as follows:

/ * encapsulate 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 ($fields)-> 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 fields $query = $this- > db- > update ($table,$data,$where); return $query;} / * * self-increment and subtraction of the extended database function * using:* $table=' codeuser' $where=array ('id'= > 1); $data=array (' usestate'= > 'usestate+1','imgtype' = >' imgtype-1'); * / public function update_count ($table ='', $where=array (), $data=array ()) {/ / return false if ('= = $table | | empty ($data)) {return false if the table name is empty or the data is empty } 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 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." The debugging information of the method is as follows:\ r\ n "; $error. = $org_error;file_put_contents (". / error_log.txt ", $error."\ r\ n ", FILE_APPEND);}} these are all the contents of the article" CI Framework Common function Encapsulation ". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Functions encapsulation queries commonly used frameworks content articles data results learning help updates information fields controllers databases methods easy to understand more organized Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker Shulou Tech Info Microsoft NVidia Redmi