In this PHP tutorial I show you how to get json data from file and insert into mysql table. If suppose friends you have lots of data into json format data, so I have make one simple php script that get data from json file and then after it will insert into database table. Following are the steps in PHP Script for Import JSON file data into Mysql Database table.
1. First we have make database connection in PHP Script by using mysqli_connect() function.
2. Second we have read JSON data file in PHP Code by using file_get_contents() function.
3. Third We have convert JSON string to PHP Array by using json_decode() function in our PHP Script.
4. Fourth We have extract PHP Array data by using foreach loop.
5. Fifth in foreach loop we have make multiple Insert query and append into one variable.
6. Then after we have run all Insert query by using mysqli_multi_query() function.
So, this way we have simple way to get data from JSON file and imported into Mysql Database. We have convert JSON data to Msyql by using PHP by follow above steps and you will understand the concept like how to read json file and how to convert json file data to array and how to insert multiple json array data into mysql database. This all things we have discuss in this post.