Import Text Files

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
Stelios
Forum Commoner
Posts: 71
Joined: Fri Feb 06, 2004 6:25 am
Location: Surrey/UK

Import Text Files

Post by Stelios »

Hi there,

What I want to do is to import a text file into a mysql db. What I mean is that instead inputing the whole text directly into the db I want to input the name of the file and then when I call it from the script to show me the contents of the file instead of its name. I understand that this is possible, but could someone please help me?

Thanks a lot! :D
djot
Forum Contributor
Posts: 313
Joined: Wed Jan 14, 2004 10:21 am
Location: planet earth
Contact:

Post by djot »

-
Confusing description of what you need...

Do you want to store the text files data in the database?
Or just the filename?

Or whatever? :)

djot
-
User avatar
Stelios
Forum Commoner
Posts: 71
Joined: Fri Feb 06, 2004 6:25 am
Location: Surrey/UK

Post by Stelios »

just the filenames but then be able to retrieve the content as well
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

So you want the file's contents returned when you perform a query.. in that query? The only way it could work is having the database create a temporary table to store off the content just before returning... but that's a pointless waste of memory and speed. It should be faster and easier to just load the file's contents immediately following the query once you know the filename.
User avatar
Stelios
Forum Commoner
Posts: 71
Joined: Fri Feb 06, 2004 6:25 am
Location: Surrey/UK

Post by Stelios »

What I mean anyway, is that I want to just load the valu of the file into the database just by inserting its file name and without having to type the whole content...I dont know if am getting understood...
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

type the whole content? :? file_get_contents() will load the data for you, you just have to insert the data it returns.. I don't see the difficulty.
rdionne1187
Forum Newbie
Posts: 17
Joined: Tue Feb 01, 2005 9:30 am
Location: CT

Post by rdionne1187 »

if you want the file line by line, if that would be easier, you could use file() but that returns the file in an array, so the code could get a little beefy :( and i dont like arrays that much
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post by n00b Saibot »

I think he just wants the contents of file loaded into db. just that.
i suggest you install phpMyAdmin and use the option for loading test files
into db :)
Post Reply