I have a json file and i want to insert all data to my database.
First i am trying to get contents from json file and store in array. It takes 20 seconds.
$strJsonFileContents = file_get_contents('C:\books.json');
$array = json_decode($strJsonFileContents);
After that i prepare the insert query
$query = $db->prepare("INSERT INTO product SET
webID = ?,
name = ?,
subtitle = ?,
title = ?,
description = ?,
ISBN = ?
.
.
.
");
I create a foreach loop and execute insert query.
foreach($array->Books as $book){
$insert = $query->execute(array(
$book->p2,
$book->p3,
$book->p4
.
.
.
));
This foreach loops has 300.000 loop. It takes huge time to insert. - I didn't see finish, it made 40,000 additions in about 10 minutes.
What should I do to reduce this time to seconds? It is not a big problem for me to have 20 seconds to read from the file but inserting time it is a huge problem.