CI框架更新与删除

时间:2018-04-30 19:55:50   收藏:0   阅读:8799

$this->load->database();
        // $query=$this->db->get(‘t_repayments‘);
        // $result = $query->result();
        // var_dump($query);


        $data=array(
            // ‘card_no‘=>‘3001‘,
            ‘this_date‘=>"5-7",
            "this_money"=>‘2431‘,
            ‘remark‘=>‘update第三个参数测试‘,
            ‘is_done‘=>1
        );

        //replace() 参数中有主键,就替换掉原来的记录,没有主键就新增一条记录。
        //没有指定条件 就是新增一条记录
        //this->db->where 对于replace()函数无效
        // $this->db->replace(‘t_repayments‘,$data);


        //set()

        // $remark ="set函数测试";
        //string参数演示
           // $this->db->set(‘remark‘,$remark);

           //数组参数测试
           //不加where() 会修改所有的数据
           // $this->db->set($data);
           // $this->db->where(‘card_no‘,‘3001‘);
           // $this->db->update(‘t_repayments‘);


           //update() 测试
           // $this->db->where(‘card_no‘,‘3001‘);
           // $this->db->update(‘t_repayments‘,$data);

        //使用update()的第三个参数 设置where子句--字符串形式
        // $this->db->update(‘t_repayments‘,$data,‘card_no=3001‘);
        // //同上-- 数组形式
        // $card_no = ‘3002‘;
        // $this->db->update(‘t_repayments‘,$data,  array(‘card_no‘=>$card_no) );

        //update_batch() 根据提供的数组或list 批量修改
        // $data = array(
        //     array(
        //         ‘card_no‘=>‘3003‘,
        //         ‘this_date‘=>‘4-2‘,
        //         ‘this_money‘=>‘990‘
        //     ),
        //     array(
        //         ‘card_no‘=>‘3002‘,
        //         ‘this_date‘=>‘4-5‘,
        //         ‘this_money‘=>‘991‘,
        //         ‘remark‘ => ‘批量修改测试‘

        //     )

        // );

        // $this->db->update_batch(‘t_repayments‘,$data,‘card_no‘);

        //删除测试
        $pk = "3001";
        // $this->db->delete(‘t_repayments‘,array(‘card_no‘=>$pk));

        $this->db->where(‘card_no‘,$pk);
        $this->db->delete(‘t_repayments‘);

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!