实例 <?php namespace app\index\controller; use think\Db; class Clin{ // 数据查询 public function findR(){ $re = Db::table('user') -> find(); dump($re); } public function selectR1(){ $re = Db::table('user') -> select(); dump($re); } public function selectR2(){ $re = Db::table('user') -> select(6); dump($re); } public function selectR3(){ $re = Db::table('user') -> where('id = 6') -> select(); dump($re); } public function selectR4(){ $re = Db::table('user') -> field('id,username,create_time') -> select(); dump($re); } public function selectR5(){ $re = Db::table('user') -> field('id, username as 用户名, create_time as 创建时间') -> select(); dump($re); } public function selectR6(){ $re = Db::table('user') -> field(['id','username'=>'用户名','create_time'=>'创建时间']) -> select(); dump($re); } public function selectR7(){ $re = Db::table('user') -> field('id,username,create_time') -> order('create_time desc') -> select(); dump($re); } public function selectR8(){ $re = Db::table('user') -> field('id,username,create_time') -> order('create_time','asc') -> select(); dump($re); } public function selectR9(){ $re = Db::table('user') -> where('id','15') -> select(); dump($re); } public function selectR10(){ $re = Db::table('user') -> where('id','<','5') -> select(); dump($re); } public function selectR11(){ $re = Db::table('user') -> where('id','<','8') -> limit(3) -> select(); dump($re); } public function in(){ $data = [ 'name' => '李白', 'sex' => 1, 'age' => 19, 'salary' => 6379 ]; $re = Db::table('staff') -> data($data) -> insert(); $id = Db::getLastInsID(); return $re.' >> '.$id; } public function ing(){ $data = [ 'name' => '李灵', 'sex' => 1, 'age' => 19, 'salary' => 6379 ]; $re = Db::table('staff') -> insertGetId($data); return $re; } public function ins(){ $data = [ ['name'=>'杜甫','sex'=>1,'age'=>32,'salary'=>4920], ['name'=>'诗人','sex'=>0,'age'=>5,'salary'=>53434], ]; $re = Db::table('staff') -> data($data) -> insertAll(); return $re; } public function update(){ $re = Db::table('staff') -> where('salary','>=',8500) -> data(['salary' => Db::raw('salary-1000')]) -> update(); return $re; } public function del(){ $re = Db::name('staff') -> delete(12); return $re; } public function dels(){ $re = Db::name('staff') -> delete([1,5,9]); return $re; } } 运行实例 » 点击 "运行实例" 按钮查看在线实例