????:創(chuàng)建一張表,用查詢構(gòu)造器中的CURD對其進行操作insert操作:public function insert(){ // 增加多條數(shù)據(jù) $data=[ ['title'=>'Php從入門到放棄','price
創(chuàng)建一張表,用查詢構(gòu)造器中的CURD對其進行操作
insert操作:
public function insert(){ // 增加多條數(shù)據(jù) $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.'條數(shù)據(jù)'; }
delete操作:
public function delete(){ //刪除數(shù)據(jù) $res=DB::table('shop')->where('price','>=',50)->delete(); return '成功刪除了'.$res.'條數(shù)據(jù)'; }
Updata
public function update(){ $res=DB::table('shop') ->where('size','中') ->data('size','小') ->update(); return '成功修改了'.$res.'條數(shù)據(jù)'; }
select查詢操作
public function find(){ $res=DB::table('shop') ->field(['id,title']) ->where('price','>',20) ->select(); dump($res); echo '成功查詢到了'.count($res).'條數(shù)據(jù)'; }public function find(){ $res=DB::table('shop') ->field(['id,title']) ->where('price','>',20) ->select(); dump($res); echo '成功查詢到了'.count($res).'條數(shù)據(jù)'; }
?? ???:查無此人?? ??:2019-03-04 09:13:06
???? ??:完成的不錯。 where('price','>=',50) where最好用數(shù)組。