how to insert json data into mysql using php

how to insert json data into mysql using php : PHP Script read JSON file contents and Insert into MySQL.

how to insert json data into mysql using php

first of all, created a Multi JSON file and write the file by the PHP source code. Creating Data in the JSON Field. Now, you are going to make products to add to the database using INSERT INTO and VALUES.

Do you want to know how a JSON file looks like? Well here is the sample json Data File.

{
    "memberid": "SJ011MS",
    "individual": {
        "name": "Virat Kohali",
        "gender": "Male",
        "age": "32",
        "apartment": {
            "streetapartment": "8 19th Street",
            "city": "Gujrat",
            "state": "GJ",
            "zip": "10038"
        }
    },
    "account": {
        "appointment": "Manager Sinors",
        "section": "Finance"
    }
}

Step 1: Connect PHP to MySQL Database


Step 2: Read the JSON file in PHP


Step 3: Convert JSON String into PHP Array


Step 4: Extract the Array Values


Step 5: Insert JSON to MySQL Database with PHP Code


Don’t Miss : how to store json data in mysql using php

Insert JSON data into MySQL using php

Complete PHP Script (index.php)


memberdetails.json

{
    "memberid": "SJ011MS",
    "individual": {
        "name": "Virat Kohali",
        "gender": "Male",
        "age": "28",
        "apartment": {
            "streetapartment": "8 19th Ambuja",
            "city": "Rajkot",
            "state": "GJ",
            "zip": "360002"
        }
    },
    "account": {
        "appointment": "Deputy General",
        "section": "Finance"
    }
}

I hope you get an idea about how to insert json data into mysql using php.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Leave a Comment