Posted By

paschim on 09/18/10


Tagged

excel


Versions (?)

importing excel to mysql db


 / Published in: PHP
 

  1. $file = fopen("myfile.csv", "r");
  2. $sql = "INSERT INTO table(field1, field2, field3...";
  3. while(!feof($file))
  4. {
  5. $fields = explode(',', fgets($file));
  6. $sql .= "VALUES("
  7. foreach($fields as $field)
  8. {
  9. $sql .= "$field, ";
  10. }
  11. $sql = substr($sql, 0, -2);
  12. $sql .= "), ";
  13. }
  14. $sql = substr($sql, 0, -2);
  15. fclose($file);
  16. mysql_query($sql);

Report this snippet  

You need to login to post a comment.