Switch to full style
:read: Start PHP with us. Includes topics to help you in php
Post a reply

Loading table data from a CSV file

Mon Oct 27, 2008 6:33 pm

Code:

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





Post a reply
  Related Posts  to : Loading table data from a CSV file
 NULL Data in table     -  
 Delete data from database table in php     -  
 show table data by clicking button     -  
 How to merge the data into file     -  
 How to make PHP form data saved into txt file     -  
 Reading selected data from a source file     -  
 Show loading image from JQuery     -  
 show loading status message until the applet is fully loaded     -  
 Encrypt/Decrypt a file from source file to target file.     -  
 Copy file to file in java code- implementation     -  

Topic Tags

PHP Files and I/O, PHP Database