2011-12-13 152 views
0

我在我們的網絡服務器上有一個.txt文件,該文件被更新並由客戶端的第三方屬性軟件取代。如何讀取和導入.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" 

我的字段名稱完全匹配,這些頭。

+0

是不是說txt一個csv其實呢? – mishu

+0

是的,相同的格式...但文件是'xfile.txt' – Adam

+0

這並不重要..我正在談論的格式..如果你把它重命名爲.jpg它不會使它成爲一張圖片..有很多解決方案可以將csv導入數據庫(並且您已經有答案),我只是想通過清除此問題,人們會更好地理解 – mishu

回答

3

可以使用MYSQL LOAD DATA INFILE直接看到MySQL Reference

這將節省來的腳本時間,會比通過一個PHP腳本導入它快得多。

1

你也可以用PHP解析它。 它看起來像一個csv。我想用fgetcsv()解析文件。

相關問題