创建一张表,用查询构造器中的CURD对其进行操作
insert操作:
public function insert(){ // 增加多条数据 $data=[ ['title'=>'Php从入门到放弃','price'=>35,'color'=>'红','size'=>'中'], ['title'=>'Java从入门到放弃','price'=>55,'color'=>'黄','size'=>'小'], ['title'=>'Css从入门到放弃','price'=>64,'color'=>'青','size'=>'大'], ['title'=>'JavaScript从入门到放弃','price'=>23,'color'=>'绿','size'=>'中'], ['title'=>'Python从入门到放弃','price'=>65,'color'=>'蓝','size'=>'中'], ['title'=>'C++从入门到放弃','price'=>123,'color'=>'紫','size'=>'小'], ['title'=>'C语言从入门到放弃','price'=>98,'color'=>'黑','size'=>'小'], ['title'=>'VB从入门到放弃','price'=>35,'color'=>'白','size'=>'大'] ]; $res=DB::table('shop')->data($data)->insertAll(); return '成功增加了'.$res.'条数据'; }
delete操作:
public function delete(){ //删除数据 $res=DB::table('shop')->where('price','>=',50)->delete(); return '成功删除了'.$res.'条数据'; }
Updata
public function update(){ $res=DB::table('shop') ->where('size','中') ->data('size','小') ->update(); return '成功修改了'.$res.'条数据'; }
select查询操作
public function find(){ $res=DB::table('shop') ->field(['id,title']) ->where('price','>',20) ->select(); dump($res); echo '成功查询到了'.count($res).'条数据'; }public function find(){ $res=DB::table('shop') ->field(['id,title']) ->where('price','>',20) ->select(); dump($res); echo '成功查询到了'.count($res).'条数据'; }