在thinkphp5中数据库操作方法如下:
一、查询
//引入类库
use think\Db;
//单个查询条件
$id = 1;
$res = Db::table('user')->where('id', $id)->find();
//多个查询条件
$map['query1'] = '1';
$map['query2'] = '2';
$res=Db::table('user')->where($map)->find();
二、更新
//引入类库
use think\Db;
$map['query2'] = '2';
$res = Db::table('user')->where($map)->update(['update1' => 1, 'update2' => 2]);
三、插入
//引入类库
use think\Db;
$data = ['foo' => 'bar', 'bar' => 'foo'];
$result = Db::table('user')->insert($data);
640



被折叠的 条评论
为什么被折叠?



