返回创建一张表,用......登陆

创建一张表,用查询构造器中的CURD对其进行操作

善為2019-03-04 06:32:02279

创建一张表,用查询构造器中的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.'条数据';
}

insert.png

delete操作:

public function delete(){
   //删除数据
   $res=DB::table('shop')->where('price','>=',50)->delete();
    return '成功删除了'.$res.'条数据';
}

delete.png

Updata

public function update(){
    $res=DB::table('shop')
        ->where('size','中')
        ->data('size','小')
        ->update();
    return '成功修改了'.$res.'条数据';
}

updata.png


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).'条数据';
}

select.png

最新手记推荐

• 用composer安装thinkphp框架的步骤• 省市区接口说明• 用thinkphp,后台新增栏目• 管理员添加编辑删除• 管理员添加编辑删除

全部回复(0)我要回复

暂无评论~
  • 取消回复发送