title: Import JSON data into database(MySQL) using PHP
body: <p>I am writing a script in PHP to directly import data from a JSON file directly into a MySQL database. My sample data at the moment is pretty small. I have a few questions about it. I would like to do this without external packages. If you know or have a code sample I can look at that would be very helpful.</p>
  <ol>
  <li>How can I make it work with very large data sets? Break it up in
  chunks? Import it line by line? Use fopen?</li>
  <li>If during it's run the script get interrupted for some reason, is
  there a way to make sure it continues where it left of? How would you do this?</li>
  <li>If I want to remove duplicates with the same emails should I do it
  during the import or maybe after with a SQL query?</li>
  <li>Would this work with XML and CSV as well?</li>
  </ol>
  <p>DATA</p>
  <pre><code>[
    {
    &quot;id&quot;:1,
    &quot;name&quot;:&quot;Mike&quot;,
    &quot;email&quot;:&quot;mike@businessweek.com&quot;
    },
    {
    &quot;id&quot;:2,
    &quot;name&quot;:&quot;Nick&quot;,
    &quot;email&quot;:&quot;nick@businessweek.com&quot;
    }
  ]
  
  </code></pre>
  <pre><code>$jsondata = file_get_contents('data.json');
  
  $data = json_decode($jsondata, true);
  
  foreach ($data as $row) {
  
      $query = 'INSERT INTO `member` (`name`, `email`) VALUES (?, ?)';
  
      $statement = $pdo-&gt;prepare($sql);
  
      $statment-&gt;execute([$row['name'], $row['email']]);
  
  }
  
  </code></pre>