zoukankan      html  css  js  c++  java
  • laravel 查询构造器

    //查询构造器
    public function query()
    {
    $bool = DB::table('student')->insert([
    ['name' => '王五', 'age' => 17, 'gender' => 1],
    ['name' => '王五2', 'age' => 17, 'gender' => 1]
    ]);
    var_dump($bool);

    //获取插入的数据的id
    $student_id = DB::table('student')->insertGetId(
    ['name' => '赵六', 'age' => 19, 'gender' => 2]
    );
    var_dump($student_id);


    //更新数据,返回影响的行数
    $num = DB::table('student')->where('id',1)->update(
    ['age' => 20, 'gender' => 2]
    );
    var_dump($num);

    //更新数据,自增字段,返回影响的行数
    $num = DB::table('student')->where('id',1)->increment('age');//自增1
    $num = DB::table('student')->where('id',1)->increment('age',3);//自增3
    $num = DB::table('student')->where('id',1)->decrement('age',3);//自减3
    var_dump($num);

    //更新数据,自增以及其他字段修改
    $num = DB::table('student')->where('id',1)->increment('age',3,['name'=>'haha']);

    //删除数据,返回删除的行数
    $num = DB::table('student')->where('id',1)->delete();
    $num = DB::table('student')->where('id','>=',10)->delete();

    //清空数据,不返回任何东西
    $num = DB::table('student')->truncate();

    }
  • 相关阅读:
    linux Segmentation faults 段错误详解
    linux cut
    linux sed
    linux tr
    linux ar
    objdump--反汇编查看
    linux中dd命令
    readelf
    登录后,前端做了哪些工作,如何得知已登录?
    正向代理和反向代理?
  • 原文地址:https://www.cnblogs.com/gyfluck/p/9037395.html
Copyright © 2011-2022 走看看