I have been following a solution (How to insert json array into mysql database) into how to insert JSON data into a MySQL table. The code seems to run okay but it is still returning an empty data set.
I'm currently testing a hypothesis and my JSON file has 100,000 records in it. I have created a similar JSON file with just three records thinking that the size of the file may have been impeding it but that didn't work either.
I have checked my database name, table name and row names but is correct with the code shown. Any pointers?
<?php
$json = file_get_contents('E:\xampp\htdocs\MOCK_DATA.json');
$obj = json_decode($json, true);
$connection = mysqli_connect("localhost", "root", "");
mysqli_select_db($connection, "et_test") or die('Couldnt connect database');
foreach($obj as $item)
{
mysqli_query($connection, "INSERT INTO 'et_test'.'test' (first_name, last_name, colour, country, city)
VALUES ('".$item['first_name']."','".$item['last_name']."','".$item['colour']."','".$item['country']."','".$item['city']."')");
}
mysqli_close($connection);
?>