분류 php

Loading table data from a CSV file

컨텐츠 정보

  • 조회 705 (작성일 )

본문

<?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();

?>

 

php