网站制作学习网PHP→正文:thinkphp6批量update更新
字体:

thinkphp6批量update更新

PHP 2022/6/13 23:14:21  点击:不统计

http://%77%77%77%2E%66网站制作%6F学习网%72%61%73%70%2E%63%6E
 thinkphp6如何进行数据的批量更新,其实很简单

1.使用Db类操作
要使用Db类必须使用门面方式(think\facade\Db)调用,需要线引入该类
use think\facade\Db;
批量调用更新
比如把forasp表中字段cn 更新为www,筛选条件为 site=wwwforaspcn
<?php
use think\facade\Db;
....
public function update(){
  $data['cn']='www';
  Db::table('forasp')->where(['site','=','wwwforaspcn'])->update($data)
 
}
2.通过模型model进行操作,需要先建立模型,然后引入模型
比如
use think\model\forasp;
...
public function update(){
  $data['cn']='www';
  Forsap::where(['site','=','wwwforaspcn'])->update($data)
}
以上就是thinkphp6 批量更新数据库代码例子

学习www.网for站asp制.cn作

·上一篇:thinkphp6 获取public目录地址 >>    ·下一篇:thinkphp6 关闭trace >>
推荐文章
最新文章