laravel 查询构造器
2024-09-30 05:41:35
//查询构造器
public function query()
{
$bool = DB::table('student')->insert([
['name' => '王五', 'age' => 17, 'gender' => 1],
['name' => '王五2', 'age' => 17, 'gender' => 1]
]);
var_dump($bool); //获取插入的数据的id
$student_id = DB::table('student')->insertGetId(
['name' => '赵六', 'age' => 19, 'gender' => 2]
);
var_dump($student_id); //更新数据,返回影响的行数
$num = DB::table('student')->where('id',1)->update(
['age' => 20, 'gender' => 2]
);
var_dump($num); //更新数据,自增字段,返回影响的行数
$num = DB::table('student')->where('id',1)->increment('age');//自增1
$num = DB::table('student')->where('id',1)->increment('age',3);//自增3
$num = DB::table('student')->where('id',1)->decrement('age',3);//自减3
var_dump($num); //更新数据,自增以及其他字段修改
$num = DB::table('student')->where('id',1)->increment('age',3,['name'=>'haha']); //删除数据,返回删除的行数
$num = DB::table('student')->where('id',1)->delete();
$num = DB::table('student')->where('id','>=',10)->delete(); //清空数据,不返回任何东西
$num = DB::table('student')->truncate(); }
最新文章
- JFinal学习
- web测试安全性常见问题
- (实用篇)PHP递归实现无限级分类
- List Copy
- leetcode 116- Populating Next Right Pointers in Each Node
- 在cmd中登录ftp服务器
- Paxos算法之旅(四)zookeeper代码解析--转载
- Hibernate + MySQL中文乱码问题
- Android获取本机IP地址
- Webpack学习笔记(一)
- swift学习 - collectionView
- Oracle12c 在windonServer2012中安装的步骤
- SQL Server Profiler的使用
- Day8--------------RPM包管理
- ACC自适应巡航控制系统介绍
- Django-基础-2-ORM
- WINDOWS中, 如何查看一个运行中的程序是64位还是32位的
- OOP⑻
- Windows server 安装
- jetty 热部署
热门文章
- python在d盘,robotframework引入seleniumlibrary报错
- a标签目标链接问题
- VS2019 KEY
- Java常见对象Object类中的个别方法
- C# 队列Queue
- iOS 第三方类库之MBProgressHUD
- 使用xib开发界面
- BZOJ 4016 最短路径树问题 最短路径树构造+点分治
- RuntimeError: Failed to init API, possibly an invalid tessdata path: E:\python36\报错
- Python2.7 在使用BSTestRunner.py时报错TypeError: unicode argument expected, got 'str'