Work:CSV to MySQL
Disclaimer
You should try the tool located at http://www.sqldbu.com/eng/sections/tips/mysqlimport.html first before attempting anything below...
Importing a CSV File to MySQL Examples
To import an Excel file to MySQL Use the Following script. Be sure to fill in the appropriate values where required.
<?php # first get a mysql connection as per the FAQ $fcontents = file ('./spreadsheet.xls'); # expects the csv file to be in the same dir as this script for($i=0; $i<sizeof($fcontents); $i++) { $line = trim($fcontents[$i]); $arr = explode("\t", $line); #if your data is comma separated # instead of tab separated, # change the '\t' above to ',' $sql = "insert into TABLENAME values ('". implode("','", $arr) ."')"; mysql_query($sql); echo $sql ."<br>\n"; if(mysql_error()) { echo mysql_error() ."<br>\n"; } } ?>
Upload a spreadsheet file into the same directory as this script. Then you edit this script to put in the correct table name instead of "TABLENAME".
So long as your xls file is tab delimited and has 1 row per line with all columns in the same order that your mysql database columns are, then this script will pull all the data out of your XLS file and insert it all into mysql. Don't forget to connect to mysql in the script before anything else with a mysql_connect() and mysql_select_db() as shown here http://www.modwest.com/help/kb6-60.html