Insert JSON data MySQL

Today, We want to share with you Insert JSON data MySQL.In this post we will show you how to store json data in mysqli using php, hear for store json data in mysqli.

how to insert json data into mysql

we will give you demo and example for implement.In this post, we will learn about Google API Line Chart with JSON PHP with an example.

Also Read This πŸ‘‰   PHP Connection Mysql Database Steps

Step: 1 Create Database and Table

//create  database
CREATE DATABASE members_list;
USE members_list;
//create  table JSON
firstName CHAR( 50 ) NOT NULL ,
lastName CHAR( 50 ) NOT NULL

Step: 2 Create a JSON file

{"FirstName":"krishna", "LastName":"Kakadiya"}

Step: 3 PHP Script read JSON file contents and Inserts into MySQL

$connect= new mysqli($host,$user,$pass,$db) or die("ERROR:could not connect to the database!!!");


//To display all values from JSON file
$query="insert into json values('','$array[FirstName]','$array[LastName]')";


echo "Data Imported Sucessfully from JSON!";

how to inserts json data into mysql using php?


$josndata = '{
"member":{ "name":"Rekha", "department":"MCA BASE", "ContactNo":9XXXXXXXX5 }

// Database connection
$conn = new mysqli('localhost', 'username', 'password', 'databasename');

// Inserts data Query
$sql = "INSERT INTO member_table ( name, jsondata )
VALUES ('Rekha', '$josndata')";

if ($conn->query($sql) === TRUE) {
  echo "Insert your JSON record successfully";

I hope you get an idea about Inserts JSON data MySQL.
I would like to have feedback on my 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.