Looping through all csv files in a directory, pull

2019-07-30 02:42发布

问题:

I am trying to write a php script that will read all columns from a directory full of 1000 csv files (all of these files have like columns) and take all the data that it gets from the csv files and then insert it into a mysql database. I have tried writing this 3 different ways after going through tutorials online but I just cannot get it to work.

I am new to PHP so I have no idea what is going on. Is there an easy way to loop through a directory full of 1000 csv files, read in all the data from the files, and then insert the data into a mysql database?

回答1:

Here is parser How to parse a CSV file using PHP instead of echo you should push to array data, that after fetching to insert bulk into database. Also additionaly you have iterate through all your 1000 files. http://www.php-dev-zone.com/2013/05/how-to-import-csv-file-data-into-mysql.html something like that