Import JSON test
localhost
// Username => root
// Password => empty
// Database name => test
// Passing these 4 parameters
$connect = mysqli_connect("mysql61.unoeuro.com", "jnipper_dk", "AzEf6yBwRxakmdn5h2bD", "jnipper_dk_db");
$query = '';
$table_data = '';
// json file name
$filename = "college_subjects.json";
// Read the JSON file in PHP
$data = file_get_contents($filename);
// Convert the JSON String into PHP Array
$array = json_decode($data, true);
// Extracting row by row
foreach($array as $row) {
// Database query to insert data
// into database Make Multiple
// Insert Query
$query .=
"INSERT INTO student VALUES
('".$row["name"]."', '".$row["gender"]."',
'".$row["subject"]."'); ";
$table_data .= '
| '.$row["name"].' |
'.$row["gender"].' |
'.$row["subject"].' |
'; // Data for display on Web page
}
if(mysqli_multi_query($connect, $query)) {
echo '
Inserted JSON Data
';
echo '
| Name |
Gender |
Subject |
';
echo $table_data;
echo '
';
}
?>