Just beginning to learn Php,medoo insert multiple data as mentioned in the Insert document:
$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"] ]]);
Ask the great God, how do you insert post data into the database? Can you give me a simple demo? Thank you very much!
The data for the post is roughly as follows:
{ "name" : "xiaoming", "age" : 20},{ "name" : "lihong", "age" : 25}
I have tried many times, did not succeed, I hope the great God can answer, thank you
Reply content:
Just beginning to learn Php,medoo insert multiple data as mentioned in the Insert document:
$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"] ]]);
Ask the great God, how do you insert post data into the database? Can you give me a simple demo? Thank you very much!
The data for the post is roughly as follows:
{ "name" : "xiaoming", "age" : 20},{ "name" : "lihong", "age" : 25}
I have tried many times, did not succeed, I hope the great God can answer, thank you
If it is not a form submission, which means that the content-type of the request header is not equal to application/x-www-form-urlencoded or Multipart/form-data, PHP There is no way to automatically parse the data you pass over and assign values to $_post. At this point you need to use to php://input
get all the content passed in and parse the data manually.
Let's say the data you've passed is:
[ {"name": "xiaoming", "age": 20}, {"name": "lihong", "age": 25}]
So you can write:
$_POST = json_decode( file_get_contents('php://input'), true);$last_user_id = $database->insert("account", $_POST);
Besides Medoo, what kind of database Tools does PHP have?