abstract:<?php namespace app\index\controller; use think\Db; class Query { public function find() { //查询单条记录数 $res = Db::table('staff') ->field([
<?php namespace app\index\controller; use think\Db; class Query { public function find() { //查询单条记录数 $res = Db::table('staff') ->field(['name'=>'姓名','sex','salary']) ->where('staff_id','=',10) ->find(); dump($res); } public function select() { //查询多条记录 $res = Db::table('staff') ->field(['name'=>'姓名','sex,salary']) // ->where('salary > 3000') ->where('salary', '>',3000)//表达式 ->order('salary', 'DESC') ->select(); dump($res); } public function insert() { ) $data=[ 'name'=>'胡三刀', 'sex'=>0, 'age'=>32, 'salary'=>6200 ]; $data = [ ['name'=>'刘备','sex'=>0,'age'=>45,'salary'=>9000], ['name'=>'关羽','sex'=>0,'age'=>42,'salary'=>8000], ]; $num = Db::table('staff')->data($data)->insertAll(); return $num? '添加成功,新增了'.$num.'条记录':'没有记录被添加'; } public function update() { $num = Db::table('staff') ->update(['sex'=>1,'staff_id'=>17]); return $num? '更新成功'.$num.'条记录':'没有记录被更新'; } public function delete() { $num = Db::table('staff')->where('staff_id',19)->delete(); return $num ? '删除成功'.$num.'条记录':'没有记录被删除'; } }
Correcting teacher:西门大官人Correction time:2019-04-22 10:26:18
Teacher's summary:作业写的很好,在thinkphp中,Db类的使用,记得一定要加use think\Db。