Adam
Adam

Reputation: 1475

How can I read and import .txt file into database?

I have a .txt file on our webserver which gets updated and replaced by the client's third party property software.

Does anyone have a script (PHP/MySQL) where I can read this file and import it into a table in my database? Ideally something using codeigniter, but standard PHP will work just fine too.

It is in this format:

"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"

My field names match these headers exactly.

Upvotes: 0

Views: 916

Answers (2)

LordOfBerlin
LordOfBerlin

Reputation: 66

You may also parse it with PHP. It looks like a csv.

I would use fgetcsv() to parse the file.

Upvotes: 1

konsolenfreddy
konsolenfreddy

Reputation: 9671

You can use the MYSQL LOAD DATA INFILE directly, see MySQL Reference

This will save come scripting time and will be much faster than importing it via a PHP script.

Upvotes: 3

Related Questions