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);

  • 相关阅读:
    雅虎天气API调用
    HttpOperater
    HttpOperater-模拟HTTP操作类
    页面局部加载,适合Ajax Loading场景(Demo整理)
    FTPHelper-封装FTP的相关操作
    使用SOCKET实现TCP/IP协议的通讯
    IIS目录禁止执行权限
    Oracle10g 安装步骤
    SQL Server 2008、SQL Server 2008R2 自动备份数据库
    SQL列转行
  • 原文地址:https://www.cnblogs.com/paopao123/p/10749015.html
Copyright © 2011-2022 走看看