特殊条件查询

find_in_set

生成条件 find_in_set(1, name)

? 代表参数绑定,可以直接写明条件,第二个参数不传递即可,但需要注意防范注入风险

  1. $data = Model::create()->where("find_in_set(?, name)", [1])->get();

复杂where or

  1. // 生成大概语句:where status = 1 AND (id > 10 or id < 2)
  2. Model::create()->where('status', 1)->where(' (id > 10 or id <2) ')->get();

lock table

  1. Model::create()->func(function ($builder){
  2. // ...
  3. $builder->lockTable("tableName");
  4. // ...
  5. });

释放表锁

  1. Model::create()->func(function ($builder){
  2. // ...
  3. $builder->unlockTable();
  4. // ...
  5. });

select for update

  1. Model::create()->get(function ($builder){
  2. // ...
  3. $builder->selectForUpdate();
  4. // ...
  5. });