anyuan2002.com - vwin网

查找: 您的方位主页 > 电脑频道 > 编程代码 > 阅览资讯:怎么运用codelgniter结构进行增修正查操作?

怎么运用codelgniter结构进行增修正查操作?

2017-08-24 07:35:10 来历:www.anyuan2002.com 【

怎么运用codelgniter结构进行增修正查操作?

本文实例叙述了CodeIgniter结构根本增修正查操作。共享给咱们供咱们参阅,具体如下:

关于codeigniter的增修正,在此我用自己的一个例子来阐明一下:

创立数据库:

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');
   //留意假如你回来的是以下内容的话,他便是一个目标的成果集,这样当你回来controller中时,你就得转化;
//   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 "刺进数据成功";
   }else{
    echo "刺进数据失利";
   }
  }
  //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

期望本文所述对咱们根据CodeIgniter结构的PHP程序设计有所协助。

vwin娱乐场

本文地址:http://www.anyuan2002.com/bcdm/91501.html
Tags: 结构 CodeIgniter 根本
修改:vwin网
m88 188bet uedbet 威廉希尔 明升 bwin 明升88 bodog bwin 明升m88.com 18luck 188bet unibet unibet Ladbrokes Ladbrokes casino m88明升 明升 明升 m88.com 188bet m88 明陞 uedbet赫塔菲官网 365bet官网 m88 help
推行内容
引荐阅览
抢手引荐
引荐文章
关于咱们 | 联络咱们 | 友情链接 | 网站地图 | Sitemap | App | 回来顶部