Blogger Information
Blog 31
fans 0
comment 0
visits 24374
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
Day45-2018/1/20(tp5.1框架MVC实现数据库增删改查 )
SmallKing的博客
Original
928 people have browsed it

数据库增删改查 利用TP5.1框架的MVC结构实现。

model文件

<?php
namespace app\index\model;
use think\Model;
class User1 extends Model
{
}

controller文件

<?php
namespace app\index\controller;
use app\index\model\User1;

class Demo7
{
    //数据库模型查找单条数据
    public function get()
    {
        $res=User1::Where('id','=',50)
            ->field(['id'=>'学号','name'=>'姓名'])
            ->find();
        dump($res);
    }
    //数据库模型查找多条数据
    public function select()
    {
        $res=User1::Where('id','<',50)
            ->select();
        dump($res);
    }
    //数据库模型更新数据
    public function updata()
    {
        $res=User1::Where('id','=',1)
            ->update(['name'=>'哇咔']);
        dump($res);
    }
    //数据库模型插入数据
    public function insert()
    {
        $data=[
            'name'=>'挖挖',
            'email'=>'wawa@php.cn',
            'password'=>sha1(123)];
        $res=User1::insert($data);
        dump($res);
    }
    //数据库模型删除数据
    public function delete()
    {
        $res=User1::Where('id','=',82)
            ->delete();
        dump($res);
    }
}


Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post