文章来源于网络收集而来,版权归原创者所有,如有侵权请及时联系!
insert 插入
insert
插入数据到表中
insert($table, $data)table [string]
表名.
data [array]
插入到表里的数据.
$last_user_id = $database->insert("account", [ "user_name" => "foo", "email" => "foo@bar.com", "age" => 25]);
序列化数组
默认情况下,你要将数组插入会被序列化serialize()
, 也可以使用 JSON json_encode()
.
$last_user_id = $database->insert("account", [ "user_name" => "foo", "email" => "foo@bar.com", "age" => 25, "lang" => ["en", "fr", "jp", "cn"] // => 'a:4:{i:0;s:2:"en";i:1;s:2:"fr";i:2;s:2:"jp";i:3;s:2:"cn";}']);$last_user_id = $database->insert("account", [ "user_name" => "foo", "email" => "foo@bar.com", "age" => 25, "(JSON) lang" => ["en", "fr", "jp", "cn"] // => '["en","fr","jp","cn"]']);
多条数据插入
可以同时插入多条数据.
$last_user_id = $database->insert("account", [ [ "user_name" => "foo", "email" => "foo@bar.com", "age" => 25, "city" => "New York", "(JSON) lang" => ["en", "fr", "jp", "cn"] ], [ "user_name" => "bar", "email" => "bar@foo.com", "age" => 14, "city" => "Hong Kong", "(JSON) lang" => ["en", "jp", "cn"] ]]);
使用 SQL 函数
在一些特殊的情况下,您可能需要使用SQL函数来处理数据。在字段前加入#号即可
$last_user_id = $database->insert("account", [ "user_name" => "bar", "#uid" => "UUID()"]);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论