Medoo How does the framework insert JSON into a database?

Source: Internet
Author: User
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?

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.