欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

CodeIgniter框架基本增刪改查操作示例

 更新時間:2017年03月23日 14:58:51   作者:PHP__廊外詩鴿  
這篇文章主要介紹了CodeIgniter框架基本增刪改查操作,結(jié)合具體實例形式分析了CodeIgniter框架針對數(shù)據(jù)庫進(jìn)行創(chuàng)建、增刪改查等操作的相關(guān)實現(xiàn)技巧,需要的朋友可以參考下

本文實例講述了CodeIgniter框架基本增刪改查操作。分享給大家供大家參考,具體如下:

對于codeigniter的增刪改,在此我用自己的一個例子來說明一下:

創(chuàng)建數(shù)據(jù)庫:

CREATE TABLE IF NOT EXISTS `users` (
 `id` int(10) NOT NULL AUTO_INCREMENT,
 `username` varchar(50) NOT NULL,
 `password` varchar(50) NOT NULL,
 `email` varchar(100) NOT NULL,
 `fullname` varchar(100) NOT NULL,
 PRIMARY KEY (`id`),
 UNIQUE KEY `username` (`username`),
 UNIQUE KEY `email` (`email`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

Model

MTest.php

<?php
  class MTest extends CI_Model{
    public function __construct(){
      parent::__construct();
      $this->load->database();
    }
    //insert into data
    public function insert_users($arr){
      $this->db->insert('users',$arr);
    }
    //delete data
    public function delete_users($id){
      $this->db->where('id',$id);
      $this->db->delete('users');
    }
    //Alter data
    public function update_users($username,$arr){
      $this->db->where('username',$username);
      $this->db->update('users',$arr);
    }
    //select data
    public function select_users($id){
      $this->db->where('id',$id);
      $this->db->select('*');
      return $this->db->get('users');
      //注意如果你返回的是以下內(nèi)容的話,他就是一個對象的結(jié)果集,這樣當(dāng)你返回controller中時,你就得轉(zhuǎn)換;
//     return $query->result();
    }
  }
?>

Controller

home.php

<?php
/**
 * xxx.php
 * ==============================================
 * Copy right 2012-2015
 * ----------------------------------------------
 * This is not a free software, without any authorization is not allowed to use and spread.
 * ==============================================
 * @Author:YeXianMing
 * @Email:LangWaiShiGe@hotmail.com
 * @Version:zend studio10.6.2 php5.4.38 apache2.2
 */
  if(!defined('BASEPATH'))exit('No direct script access allowed');
  class Home extends CI_Controller{
    public function __construct(){
      parent::__construct();
    }
    //insert data
    public function insert(){
      $this->load->model('MTest','',TRUE);
      $arr=array('username'=>'yexianming1','password'=>'admin','email'=>'11504160314qq.com','fullname'=>'luotianyexianming');
      if(!($this->MTest->insert_users($arr))){
        echo "插入數(shù)據(jù)成功";
      }else{
        echo "插入數(shù)據(jù)失敗";
      }
    }
    //update data
    public function update(){
      $this->load->model('MTest','',TRUE);
      $arr=array('username'=>'Helloworld22','password'=>'root','email'=>'895787704@qq.com','fullname'=>'luotianyecong');
      if(!($this->MTest->update_users('Helloworld',$arr))){
        echo "修改成功";
      }else{
        echo "修改失敗";
      }
    }
    //delete data
    public function delete(){
      $this->load->model('MTest','',TRUE);
      $query=$this->MTest->delete_users(12);
      if(!$query){
        echo "刪除成功";
      }else{
        echo "刪除失敗";
      }
    }
    //select data
    public function select(){
      $this->load->library('table');
      $this->load->model('MTest','',TRUE);
      $arr=$this->MTest->select_users(3);
      $userinformation=$this->table->generate($arr);
      $data['userinfor']=$userinformation;
      $this->load->view('template',$data);
    }
  }
?>

view

temlate.php

<?php echo $userinfor;?>

output:

id username password email fullname
3 Helloworld22 root 1111111@qq.com luotianyecong

更多關(guān)于CodeIgniter相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《codeigniter入門教程》、《CI(CodeIgniter)框架進(jìn)階教程》、《php優(yōu)秀開發(fā)框架總結(jié)》、《ThinkPHP入門教程》、《ThinkPHP常用方法總結(jié)》、《Zend FrameWork框架入門教程》、《php面向?qū)ο蟪绦蛟O(shè)計入門教程》、《php+mysql數(shù)據(jù)庫操作入門教程》及《php常見數(shù)據(jù)庫操作技巧匯總

希望本文所述對大家基于CodeIgniter框架的PHP程序設(shè)計有所幫助。

相關(guān)文章

  • 在laravel框架中實現(xiàn)封裝公共方法全局調(diào)用

    在laravel框架中實現(xiàn)封裝公共方法全局調(diào)用

    今天小編就為大家分享一篇在laravel框架中實現(xiàn)封裝公共方法全局調(diào)用,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2019-10-10
  • PHP解碼unicode編碼的中文字符代碼分享

    PHP解碼unicode編碼的中文字符代碼分享

    晚上在抓取某網(wǎng)站數(shù)據(jù),結(jié)果在數(shù)據(jù)包中發(fā)現(xiàn)了這么一串編碼的數(shù)據(jù):"......\u65b0\u6d6a\u5fae\u535a......", 這其實是中文被unicode編碼后了的數(shù)據(jù),我現(xiàn)在就是想解碼出中文來,上度娘搞了半天,試了很多的姿(方)勢(法),終于搞定了。
    2014-08-08
  • CI框架網(wǎng)頁緩存簡單用法分析

    CI框架網(wǎng)頁緩存簡單用法分析

    這篇文章主要介紹了CI框架網(wǎng)頁緩存簡單用法,結(jié)合實例形式分析了CI框架網(wǎng)頁緩存的原理,以及開啟緩存、刪除緩存等操作技巧,需要的朋友可以參考下
    2018-12-12
  • php實現(xiàn)網(wǎng)站留言板功能

    php實現(xiàn)網(wǎng)站留言板功能

    這篇文章主要介紹了php實現(xiàn)網(wǎng)站留言板功能,主要仿照了暢言留言板和網(wǎng)易跟帖樣式進(jìn)行制作,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2015-11-11
  • laravel 實現(xiàn)根據(jù)字段不同值做不同查詢

    laravel 實現(xiàn)根據(jù)字段不同值做不同查詢

    今天小編就為大家分享一篇laravel 實現(xiàn)根據(jù)字段不同值做不同查詢,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2019-10-10
  • php版微信開發(fā)之接收消息,自動判斷及回復(fù)相應(yīng)消息的方法

    php版微信開發(fā)之接收消息,自動判斷及回復(fù)相應(yīng)消息的方法

    這篇文章主要介紹了php版微信開發(fā)之接收消息,自動判斷及回復(fù)相應(yīng)消息的方法,涉及基于微信消息處理接口的調(diào)用相關(guān)操作技巧,需要的朋友可以參考下
    2016-09-09
  • php腳本運(yùn)行時的超時機(jī)制詳解

    php腳本運(yùn)行時的超時機(jī)制詳解

    在我們平常的開發(fā)中,也許曾經(jīng)都遇到過PHP腳本運(yùn)行超時的情況,當(dāng)遇到這種情況我們經(jīng)常會通過使用 set_time_limit(非安全模式),或修改配置文件并重啟服務(wù)器,或者修改程序減少程序的執(zhí)行時間,使其在允許的范圍之內(nèi),以解決此問題。
    2016-02-02
  • php微信公眾平臺開發(fā)(一) 配置接口

    php微信公眾平臺開發(fā)(一) 配置接口

    這篇文章主要為大家詳細(xì)介紹了php微信公眾平臺開發(fā)第一篇,微信公眾號配置接口,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-12-12
  • php多種形式發(fā)送郵件(mail qmail郵件系統(tǒng) phpmailer類)

    php多種形式發(fā)送郵件(mail qmail郵件系統(tǒng) phpmailer類)

    這篇文章主要介紹了php多種形式發(fā)送郵件的方法,包括使用mail()函數(shù)、使用管道的形式、使用phpmailer類等方法,大家參考使用吧
    2014-01-01
  • php文件上傳及下載附帶顯示文件及目錄功能

    php文件上傳及下載附帶顯示文件及目錄功能

    這篇文章主要介紹了php文件上傳及下載附帶顯示文件及目錄功能,需要的朋友可以參考下
    2017-04-04

最新評論