插入方法:Insert API-Medoo使用指南

上一篇《選取方法:Select API-Medoo使用指南》中介紹了Medoo的Select方法,主要說明了查詢字段和錶鏈接的使用方法,本篇將介紹如何使用Insert方法把數據寫入到數據庫。php

插入方法:Inserthtml

插入新記錄到DB的表中。數據庫

insert($table, $data)
//table [string]: 表名
//data [array]:將要保存到DB中的數據.


返回值: [number]  插入DB中的最後一條記錄的id數組

 提示:你能夠直接插入數組數據,不須要序列化,由於Medoo會自動處理。
post

$database = new medoo("my_database");
 
$last_user_id = $database->insert("account", [
	"user_name" => "foo",
	"email" => "foo@bar.com",
	"age" => 25,
	"lang" => ["en", "fr", "jp", "cn"]
]);
 
// 多條記錄插入 (自Medoo 0.9起支持)
$last_user_id = $database->insert("account", [
[
	"user_name" => "foo",
	"email" => "foo@bar.com",
	"age" => 25,
	"city" => "New York",
	"lang" => ["en", "fr", "jp", "cn"]
],
[
	"user_name" => "bar",
	"email" => "bar@foo.com",
	"age" => 14,
	"city" => "Hong Kong",
	"lang" => ["en", "jp", "cn"]
]);


原文標題: 插入方法:Insert API-Medoo使用指南spa

原文連接: http://loiy.net/post/576.html.net

相關文章
相關標籤/搜索