We can insert the json data in to mySQL using php .please see the below example for processing json data to mySQL.
Example : -
Suppose we have a file having json data like below -
{"FirstName":"ravi", "LastName":"srivastva"}
For processing with json we have to first open the json file using fopen() method. Then we have to read this file using fread() function of PHP. Then decode the json data so that we can get the record in the form of array values.
Now just pass the array value to your insert query as simple as we use insert query for inserting a single record. then we can see we are able to insert data from json file to mysql databse table. please create the table and give certain column where we want to insert the values.
<?php
$host="localhost";
$user="root";
$pass="";
$db="demo";
$connect= new mysqli($host,$user,$pass,$db) or die("ERROR:could not connect to the database!!!");
$fo=fopen("json_file.json","r");
$fr=fread($fo,filesize("json_file.json"));
$array=json_decode($fr,true);
//To display all values from JSON file
//print_r($array);
$query="insert into json values('','$array[FirstName]','$array[LastName]')";
$connect->query($query);
echo "Data Imported Sucessfully from JSON!";
?>
0 Comment(s)