Posted inMysql / Mysqli / php

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.

I am Jaydeep Gondaliya , a software engineer, the founder and the person running Pakainfo. I'm a full-stack developer, entrepreneur and owner of Pakainfo.com. I live in India and I love to write tutorials and tips that can help to other artisan, a Passionate Blogger, who love to share the informative content on PHP, JavaScript, jQuery, Laravel, CodeIgniter, VueJS, AngularJS and Bootstrap from the early stage.

Leave a Reply

Your email address will not be published. Required fields are marked *

We accept paid guest Posting on our Site : Guest Post Chat with Us On Skype