码迷,mamicode.com
首页 > Web开发 > 详细

PHP的CI框架实现增删查改

时间:2016-05-22 21:22:48      阅读:162      评论:0      收藏:0      [点我收藏+]

标签:

<?php
defined(‘BASEPATH‘) OR exit(‘No direct script access allowed‘);

class Welcome extends MY_Controller {

    /**
     * Index Page for this controller.
     *
     * Maps to the following URL
     *         http://example.com/index.php/welcome
     *    - or -
     *         http://example.com/index.php/welcome/index
     *    - or -
     * Since this controller is set as the default controller in
     * config/routes.php, it‘s displayed at http://example.com/
     *
     * So any other public methods not prefixed with an underscore will
     * map to /index.php/welcome/<method_name>
     * @see https://codeigniter.com/user_guide/general/urls.html
     */
    public function index()
    {
        /*
        //查询表
        $res=$this->db->get(‘pergoods‘);
        //var_dump($res);
        foreach($res->result() as $item){
            echo $item->UserName;
            echo $item->UserID;
            echo $item->Goods;
            echo $item->GdModel;
            echo $item->GdNumber;
            echo $item->GdTime;
            echo ‘<br>‘;
        }*/
        
        
        /*
        //增加表数据
        $data=array(
            ‘UserName‘=>‘张三‘,
            ‘UserID‘=>‘123‘,
        );
        $bool=$this->db->insert(‘pergoods‘,$data);
        var_dump($bool);
        */
        
        
        /*
        //修改
        $data=array(
            ‘UserName‘=>‘李四‘,
            ‘UserID‘=>‘456‘,
        );
        
        $bool=$this->db->update(‘pergoods‘,$data,array(‘RecordID‘=>42));
        var_dump($bool);
        */
        
        
        /*
        //删除
        $bool=$this->db->delete(‘pergoods‘,array(‘RecordID‘=>42));
        var_dump($bool);
        */
        
        
        
        //连贯操作
        $res=$this->db->select(‘RecordID,UserName,UserID‘)
                ->from(‘pergoods‘)
                ->where(‘RecordID >=‘,10)  //RecordID大于等于10
                ->limit(3,2)    //跳过俩条查询三条
                ->order_by(‘RecordID desc‘)
                ->get();
        
        var_dump($res->result());
        //显示最近执行的一条sql
        echo $this->db->last_query();
        
        
    
        /*
        //where操作
        $res=$this->db->where(‘UserName‘,‘刘政‘)->get(‘pergoods‘);
        $res=$this->db->where(‘UserName !=‘,‘刘政‘)->get(‘pergoods‘);
        $res=$this->db->where(array(‘UserName‘=>‘刘政‘))->get(‘pergoods‘);
        $res=$this->db->where(array(‘UserName‘=>‘刘政‘,‘RecordID >‘=>‘10‘))->get(‘pergoods‘);
        echo $this->db->last_query();
        */

        
        //$this->load->view(‘welcome_message‘);
    }
    
}

PHP的CI框架实现增删查改

标签:

原文地址:http://www.cnblogs.com/282513967-qq/p/5517751.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!