Jump to content

upload script for multiple rows/columns


Bazzaah

Recommended Posts

Not sure if this is the right forum, but I have a database that I will need to populate with a large number of rows (2000+).

 

I have written a PHP script that uploads individual entries.

 

Is it possible to use something like a spreadsheet where I can set out the rows/columns as they will appear in the database, and then upload in one go rather than uploading each row individually?

 

Thanks for any observations and/or help.

Link to comment
https://forums.phpfreaks.com/topic/250868-upload-script-for-multiple-rowscolumns/
Share on other sites

Yes, this can be done easily by exporting your excel file to a csv and then importing that directly using mysql. Here is an example of what the query would look like:

 

LOAD DATA LOCAL INFILE '/path/to/your.csv' 
INTO TABLE `table` 
FIELDS TERMINATED BY ',' 
LINES TERMINATED BY '\n' 
(`field1`,`field2`,`field3`);

 

If I am not mistaken(it has been a while since i have done this) you will need to remove the top line from the cvs otherwise the column list at the top will also get inserted as a new row

After reading the docs I see that I forgot to add "ENCLOSED BY". This should solve the quote problem

LOAD DATA LOCAL INFILE '/path/to/your.csv' 
INTO TABLE `table`
OPTIONALLY ENCLOSED BY '"' 
FIELDS TERMINATED BY ',' 
LINES TERMINATED BY '\n' 
(`field1`,`field2`,`field3`);

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.