修改一些格式
相关信息:
- 类型:文档文章
- 文章: DB
- 文档: 《Laravel 速查表(5.8)》
此投稿已在 4年前 合并。
内容修改:
Old | New | Differences |
---|---|---|
8 | 8 | // 运行普通语句 |
9 | 9 | DB::statement('drop table users'); |
10 | 10 | // 监听查询事件 |
11 | DB::listen(function($sql, $bindings, $time) | |
11 | DB::listen(function($sql, $bindings, $time) { code_here; }); | |
12 | 12 | // 数据库事务处理 |
13 | DB::transaction(function() | |
14 | { | |
15 | DB::table('users')->update(['votes' => 1]); | |
16 | DB::table('posts')->delete(); | |
13 | DB::transaction(function() { | |
14 | DB::table('users')->update(['votes' => 1]); | |
15 | DB::table('posts')->delete(); | |
17 | 16 | }); |
18 | 17 | DB::beginTransaction(); |
19 | 18 | DB::rollBack(); |
20 | 19 | DB::commit(); |
20 | ||
21 | // 获取表前缀 | |
22 | DB::getTablePrefix() | |
21 | 23 | ``` |
22 | 24 | |
23 | 25 | ### 查询语句构造器 | … | … |
26 | 28 | // 取得数据表的所有行 |
27 | 29 | DB::table('name')->get(); |
28 | 30 | // 取数据表的部分数据 |
29 | DB::table('users')->chunk(100, function($users) | |
30 | { | |
31 | foreach ($users as $user) | |
32 | { | |
33 | ||
34 | // | |
35 | } | |
31 | DB::table('users')->chunk(100, function($users) { | |
32 | foreach ($users as $user) { | |
33 | // | |
34 | } | |
36 | 35 | }); |
37 | 36 | // 取回数据表的第一条数据 |
38 | 37 | $user = DB::table('users')->where('name', 'John')->first(); | … | … |
104 | 103 | // select * from users where name = 'John' or (votes > 100 and title <> 'Admin') |
105 | 104 | DB::table('users') |
106 | 105 | ->where('name', '=', 'John') |
107 | ->orWhere(function($query) | |
108 | { | |
106 | ->orWhere(function($query) { | |
109 | 107 | $query->where('votes', '>', 100) |
110 | 108 | ->where('title', '<>', 'Admin'); |
111 | 109 | }) |