Loading table data from a CSV file : CSV : Development PHP Source Code


PHP Source Code » Development » CSV »

 

Loading table data from a CSV file




<?php

   $conn = mysql_connect("localhost","someuser","secret");
   $db = mysql_select_db("cars");

   $fh = fopen("yourCSVFile.csv""r");
   while ($line = fgetcsv($fh, 1000",")) {
      $year = $line[0];
      $make = $line[1];
      $color = $line[2];

      $query = "INSERT INTO carcollection SET year='$year', make='$make',color='$color'";
      $result = mysql_query($query);
   }

   fclose($fh);
   mysql_close();
?>

           
       



HTML code for linking to this page:

Follow Navioo On Twitter

PHP Source Code

 Navioo Development
» CSV