zoukankan      html  css  js  c++  java
  • 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);

  • 相关阅读:
    Hadoop2.0 HA集群搭建步骤
    了解何为DML、DDL、DCL
    搭建Hadoop平台(新手入门)
    周记1
    IT小小鸟
    Python中的函数修饰符
    python_类方法和静态方法
    Python的log模块日志写两遍的问题
    python——装饰器例子一个
    初识HIVE
  • 原文地址:https://www.cnblogs.com/paopao123/p/10749015.html
Copyright © 2011-2022 走看看