1. 限定数量

一般用于查询

  1. <?php
  2. // 限定结果和数量
  3. public function limit1()
  4. {
  5. $data = Db::table('wh_record')
  6. ->where([
  7. ['IDX', '>', 150000],
  8. ['UNIT', '=', 2],
  9. ['STATUS', 'IN', ['归还', '借出']],
  10. ])
  11. ->field('IDX AS ID, BUILD AS 阶段, ISN AS 序列号, STATUS AS 状态')
  12. ->limit(10)
  13. ->select();
  14. return json($data);
  15. }

极少数情况下用于修改

  1. <?php
  2. Db::table('think_user')
  3. ->where('score',100)
  4. ->limit(3)
  5. ->update(['level'=>'A']);

2. 用于分页

  1. <?php
  2. // 用于分页
  3. public function limit2()
  4. {
  5. $data = Db::table('wh_record')
  6. ->where([
  7. ['IDX', '>', 150000],
  8. ['UNIT', '=', 2],
  9. ['STATUS', 'IN', ['归还', '借出']],
  10. ])
  11. ->field('IDX AS ID, BUILD AS 阶段, ISN AS 序列号, STATUS AS 状态')
  12. ->limit(0, 10)
  13. ->select();
  14. return json($data);
  15. }