循环遍历一个目录中的所有csv文件,从每个文件中提取信息,并将数据放在mysql数据库中 [英] Looping through all csv files in a directory, pulling info from each and putting data in mysql database

查看:1106
本文介绍了循环遍历一个目录中的所有csv文件,从每个文件中提取信息,并将数据放在mysql数据库中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想写一个php脚本,将从一个目录中读取所有列,其中包含1000个csv文件(所有这些文件都有类似的列),并从csv文件获取所有的数据,然后将其插入一个mysql数据库。我已经试过写这个3种不同的方式后,通过教程在线,但我只是不能得到它的工作。

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.

我是PHP的新手,所以我不知道发生了什么。有没有一个简单的方法来循环通过一个目录充满1000 csv文件,读取所有的数据从文件,然后将数据插入到mysql数据库?

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?

推荐答案

这里是解析器如何解析使用PHP的CSV文件而不是echo,您应该推送到数组数据,获取后将批量插入数据库。此外,您还可以遍历所有的1000个文件。 http:/ /www.php-dev-zone.com/2013/05/how-to-import-csv-file-data-into-mysql.html 类似的东西

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

这篇关于循环遍历一个目录中的所有csv文件,从每个文件中提取信息,并将数据放在mysql数据库中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆