//查询构造器
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();

}

相关文章:

  • 2021-11-06
  • 2021-07-15
  • 2021-10-19
  • 2022-01-01
  • 2021-05-24
  • 2022-02-09
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-09-03
  • 2021-06-20
  • 2022-12-23
  • 2022-12-23
  • 2022-01-08
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案