Jump to content


Photo

I want to get data from excel file and insert it into db,is there anything help about this?


  • Please log in to reply
2 replies to this topic

#1 mikeji

mikeji
  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 03 April 2006 - 05:48 AM

I want to get data from excel file and insert it into db,is there anything help about this?

#2 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 03 April 2006 - 09:32 AM

Sure... use LOAD DATA LOCAL INFILE, and specify appropriate field/row terminators for a TAB-delimited / CSV-export from your Excel file. I'm sure I've posted something like that here before; I don't remember the syntax off-hand.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#3 wickning1

wickning1
  • Members
  • PipPipPip
  • Advanced Member
  • 405 posts

Posted 03 April 2006 - 04:51 PM

If you need to do a lot of translation, you may have to read the CSV in PHP and create an SQL query on the fly. You can use the PHP functions file() and explode() to easily parse a CSV file.. You'll have to export to CSV in Excel.

Example:
foreach(file('mycsvfile.csv') as $line) {
   $row = explode(',', $line);
   $datayouwant = $row[5];
   $moredatayouwant = $row[7];
   ... INSERT ... ($datayouwant, $moredatayouwant) ...
}





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users