
image.png
1.插入操作
//單挑數(shù)據(jù)
Db::table('staff')
->insert([
'id' => '1009',
'name' => '阿朱',
'sex' => '0',
'age' => 25
]);

image.png
//多條數(shù)據(jù)
Db::table('staff')
->insertAll([
['id' => '1010', 'name' => '趙敏', 'sex' => '0', 'age' => 21],
['id' => '1011', 'name' => '張無忌', 'sex' => '1', 'age' => 25],
['id' => '1012', 'name' => '張三豐', 'sex' => '1', 'age' => 85]
]);

image.png
2.更新操作
Db::table('staff')
->where('id',1012)
->update([
'salary' => 4000
]);

image.png
3.查詢操作
查詢單條字段
$affected = Db::table('staff')
->where('id',1012)
->value('name');
dump($affected); //打印語句

image.png
更多查詢,參考我的上一篇文章:http://www.itdecent.cn/p/b8f73cce4445
4.刪除操作
Db::table('staff')
->delete(1012); //注意傳入的必須是主鍵名對應(yīng)的值,刪除多條傳入數(shù)組

image.png
Db::table('staff')
->delete(true); //情況當(dāng)前表