上一篇《选取方法: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