CI架構常用函數封裝執行個體_php執行個體

來源:互聯網
上載者:User

本文執行個體講述了CI架構常用函數封裝。分享給大家供大家參考,具體如下:

/*** 封裝查詢函數*/public function get_what($table='',$where=array(),$fields = ' * '){    if( '' == $table ){      return false;    }    //查詢並返回相關結果    $query = $this->db->select($fields)->where($where)->get($table);    $res = $query->result_array();    return $res;}/*** 封裝單條查詢函數*/public function get_row($table='',$where=array(),$fields = ' * '){    if( '' == $table ){      return false;    }    //查詢並返回相關結果    $query = $this->db->select($fields)->where($where)->get($table);    $res = $query->row_array();    return $res;}/*** 封裝更新函數*/public function update_what($table='', $where=array(), $data = array()){    if('' == $table || true === empty($where) || true === empty($data)){      return false;    }    //更新相應的欄位    $query = $this->db->update($table,$data,$where);    return $query;}/*** 擴充資料庫函數之自增 自減* using:* $table = 'codeuser';$where = array('id'=>1);$data = array('usestate'=>'usestate+1','imgtype' => 'imgtype-1');*/public function update_count($table = '', $where=array(), $data=array()){     //如果表名為空白 或者資料為空白則直接 返回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;}/*** 封裝插入函數*/public function insert_what($table = '', $data = array()){    if('' == $table || true === empty($data)){      return false;    }    //插入 相關記錄    $query = $this->db->insert($table, $data);    return $query;}/*** 刪除記錄封裝函數*/public function delete_what($table = '', $where=array()){    if(true === empty($where) || '' == $table){      return false;    }    //刪除相關表記錄    $query = $this->db->delete($table,$where);    return $query;}/*** debug 相關函數*/ 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";      $error .= $func." 方法調試資訊如下:\r\n";      $error .= $org_error;file_put_contents("./error_log.txt",$error."\r\n",FILE_APPEND);    }}

更多關於CodeIgniter相關內容感興趣的讀者可查看本站專題:《codeigniter入門教程》、《CI(CodeIgniter)架構進階教程》、《php優秀開發架構總結》、《ThinkPHP入門教程》、《ThinkPHP常用方法總結》、《Zend FrameWork架構入門教程》、《php物件導向程式設計入門教程》、《php+mysql資料庫操作入門教程》及《php常見資料庫操作技巧匯總》

希望本文所述對大家基於CodeIgniter架構的PHP程式設計有所協助。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.