摘要:創(chuàng)建一張表,用查詢(xún)構(gòu)造器中的CURD對(duì)其進(jìn)行操作insert操作:public function insert(){ // 增加多條數(shù)據(jù) $data=[ ['title'=>'Php從入門(mén)到放棄','price
創(chuàng)建一張表,用查詢(xún)構(gòu)造器中的CURD對(duì)其進(jìn)行操作
insert操作:
public function insert(){ // 增加多條數(shù)據(jù) $data=[ ['title'=>'Php從入門(mén)到放棄','price'=>35,'color'=>'紅','size'=>'中'], ['title'=>'Java從入門(mén)到放棄','price'=>55,'color'=>'黃','size'=>'小'], ['title'=>'Css從入門(mén)到放棄','price'=>64,'color'=>'青','size'=>'大'], ['title'=>'JavaScript從入門(mén)到放棄','price'=>23,'color'=>'綠','size'=>'中'], ['title'=>'Python從入門(mén)到放棄','price'=>65,'color'=>'藍(lán)','size'=>'中'], ['title'=>'C++從入門(mén)到放棄','price'=>123,'color'=>'紫','size'=>'小'], ['title'=>'C語(yǔ)言從入門(mén)到放棄','price'=>98,'color'=>'黑','size'=>'小'], ['title'=>'VB從入門(mén)到放棄','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查詢(xún)操作
public function find(){ $res=DB::table('shop') ->field(['id,title']) ->where('price','>',20) ->select(); dump($res); echo '成功查詢(xún)到了'.count($res).'條數(shù)據(jù)'; }public function find(){ $res=DB::table('shop') ->field(['id,title']) ->where('price','>',20) ->select(); dump($res); echo '成功查詢(xún)到了'.count($res).'條數(shù)據(jù)'; }
批改老師:查無(wú)此人批改時(shí)間:2019-03-04 09:13:06
老師總結(jié):完成的不錯(cuò)。 where('price','>=',50) where最好用數(shù)組。