php Tp5下mysql的增删改查

    //
    public function insert(){
        $data = array(
            "username"=>"user121",
            "password"=>"123456"
        );
        $code=Db::table('user')->insertGetId($data);
        dump($code);
    }
    
    //
    public function delete(){
        $where = array(
            'id' =>17
        );
//        $code=Db::table('user')->where('id>38 and id<40')->delete();
        $code=Db::table('user')->where($where)->delete();
        dump($code);
    }
    
    //
    public function update(){
        $data = array(
            'username' => 'fsadfsaf'
        );
        $where = array(
            'id' =>18
        );
        $code=Db::table('user')->where($where)->update($data);
        dump($code);
    }
    
    //
    public function select(Request $request){
        $where = 'id < 18';
        $field = 'username,password';
        //查询所有数据
         $data=Db::table('user')->field($field)->where($where)->select();
        dump($data);
}

in 查询 和like 查询 

in 查询

public function index(){
        $arr = array('xuzhan','user','user2','user3','user4');
        $result=Db::table("user")->where('username',"in",$arr)->select();
        dump($result);
    }

like 查询

public function index(){
    $user = '%user%';
        $result=Db::table("user")->where('username',"like",$user)->select();
        dump($result);
    }

 where 多条件查询 

            $where['username'] = ['=',$param['username']];
#$where['字段名'] = array('运算符','条件');
$where['password'] = ['=',$param['password']]; $field = 'id'; //查询所有数据 $data=Db::table('user')->field($field)->where($where)->select(); var_dump($data);

 

posted @ 2019-04-22 11:12  小跑跑泡  阅读(721)  评论(0编辑  收藏  举报