如何读取.text文件并将其导入数据库?

时间:2011-12-13 11:51:50

标签: php mysql codeigniter

我的网络服务器上有一个.txt文件,该文件会被客户的第三方财产软件更新并替换。

有没有人有一个脚本(PHP / MySQL),我可以在这里读取这个文件并将其导入我的数据库中的表中?理想情况下使用codeigniter,但标准的PHP也可以正常工作。

采用以下格式:

"BranchID","PropertyID","PropertyName","Street","DisplayStreet","Postcode","PricePrefix","Price","Bedrooms","Receptions","Bathrooms","ParkingSpaces","Numeric5","Numeric6","Numeric7","Numeric8","Numeric9","AREA","TYPE","FURNISHED","CHILDREN","SMOKING","PETS","GARDEN","DSS","PARKING","cFacility1","cFacility2","cFacility3","cFacility4","cFacility5","cFacility6","cFacility7","cFacility8","cFacility9","cFacility10","Tenure","ShortDescription","MainDescription","AvailabilityCode","AvailabilityDate","FullAddress","PricePrefixPos"

我的字段名称与这些标题完全匹配。

2 个答案:

答案 0 :(得分:3)

您可以直接使用MYSQL LOAD DATA INFILE,请参阅MySQL Reference

这将节省脚本编写时间,并且比通过PHP脚本导入脚本的速度快得多。

答案 1 :(得分:1)

您也可以使用PHP解析它。 它看起来像一个csv。

我会使用fgetcsv()来解析文件。