W3Cschool
恭喜您成為首批注冊(cè)用戶
獲得88經(jīng)驗(yàn)值獎(jiǎng)勵(lì)
查詢構(gòu)造器還提供了 insert
方法用于插入記錄到數(shù)據(jù)庫(kù)中。 insert
方法接收數(shù)組形式的字段名和字段值進(jìn)行插入操作:
DB::table('users')->insert(
['email' => 'john@example.com', 'votes' => 0]
);
你甚至可以將二維數(shù)組傳遞給 insert
方法,依次將多個(gè)記錄插入到表中:
DB::table('users')->insert([
['email' => 'taylor@example.com', 'votes' => 0],
['email' => 'dayle@example.com', 'votes' => 0],
]);
insertOrIgnore
方法在將記錄插入數(shù)據(jù)庫(kù)時(shí)將忽略重復(fù)記錄錯(cuò)誤:
DB::table('users')->insertOrIgnore([
['id' => 1, 'email' => 'taylor@example.com'],
['id' => 2, 'email' => 'dayle@example.com'],
]);
Copyright©2021 w3cschool編程獅|閩ICP備15016281號(hào)-3|閩公網(wǎng)安備35020302033924號(hào)
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號(hào)
聯(lián)系方式:
更多建議: