Posted inMysql / Mysqli / php

how to insert multiple json data into mysql database in php? – Best 3 Examples

how to insert multiple json data into mysql database in php? – MySQL INSERT statement: It is used to insert/store data into the database with Example 1. Read the JSON file in PHP, 2 – Convert JSON String into PHP Array, 3 – Extract the Array Values in Variables and last Insert JSON to MySQL Database with PHP Code.

how to insert multiple json data into mysql database in php?

first of all you can Connect PHP to MySQL Database and then Read the JSON file in PHP after that Convert JSON String into PHP Array and then Extract the Array Values & last step to Insert JSON to MySQL Database with PHP(index.php) source Code : how to insert multiple json data into mysql database in php?.

Insert JSON data into MySQL using PHP

index.php



Insert JSON Data - www.pakainfo.com


query($sql) === TRUE) {
  echo "Insert your JSON record successfully";
} 
?>


Store JSON data in MySQL Database



Store JSON Data - www.pakainfo.com


member->name;
  
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "member_lisr";

$link = new mysqli($servername, $username, $password, $dbname);

$sql = "INSERT INTO member_table ( name, jsondata )
VALUES ('Manjudi', '$singledata')";

if ($link->query($sql) === TRUE) {
  echo "Store data only single successfully";
}  
?>


Insert Multiple JSON Data into MySQL Database in Php

index.php



Insert Multiple JSON Data


query($sql) === TRUE) {
  echo "Insert your Multiple Members JSON record successfully";
} 
?>


Don’t Miss : How To Store Json Data In Mysql Using Php?

HOW TO INSERT JSON DATA INTO MYSQL USING PHP?

simple example to how to store json data in mysql using php?
Step 1: Read the JSON file in PHP

$memberjsondata = file_get_contents('members.json');

Step 2: Convert JSON String into PHP Array

$data = json_decode($memberjsondata, true);

Step 3: Extract the Array Values in Variables

$id = $data['memberId'];
$name = $data['profilebio']['name'];
$age = $data['profilebio']['age'];
$streetlocations = $data['profilebio']['locations']['streetlocations'];
$city = $data['profilebio']['locations']['city'];
$state = $data['profilebio']['locations']['state'];
$postalcode = $data['profilebio']['locations']['postalcode'];

Step 4: Insert JSON to MySQL Database with PHP Code

$sql = "INSERT INTO tbl_members(memberId, name, age, streetlocations, city, state, postalcode)
    VALUES('$id', '$name', '$age', '$streetlocations', '$city', '$state', '$postalcode')";
if(!mysqli_query($con, $sql))
{
    die('Error : ' . mysql_error());
}

members.json

{
    "memberId": "MD00548",
    "profilebio": {
        "name": "Virat Kohali",
        "age": "29",
        "locations": {
            "streetlocations": "8 12th Street",
            "city": "Rajkot",
            "state": "GJ",
            "postalcode": "98560"
        }
    }
}

I hope you get an idea about how to insert multiple json data into mysql database in 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