homepage Welcome to WebmasterWorld Guest from 54.226.230.76
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / Databases
Forum Library, Charter, Moderators: physics

Databases Forum

    
Flat Files! Please explain to someone of my likes!
JAB Creations




msg:1580398
 5:42 pm on Sep 29, 2005 (gmt 0)

From what I can tell flat file databases are basically if you just have the SQL database file sitting in a directory that can be accessed online (unless you put it in a place the server can access but not the public such as just above the public_html folder). I could be wrong, and typically am so feel free to correct me now!

I like the idea of flat files but I don't know how they work! I am trying to break in to PHP and MySQL and I know PHP as far as including files, creating strings with html in them, printing strings, creating a cookie, reading a specific cookie, basic if / else structure and I can mod a prebuilt script to setup my own database (username/password). Anything else is probably above my head depending on it's complexity.

I'm not particularly looking to learn anything too specific but to get a general idea and hopefully that might hook on to something else later on in say I dunno three or four months down the road.

Anyway I appreciate any responses I get here! Thanks! :)

 

Frank_Rizzo




msg:1580399
 11:10 pm on Sep 29, 2005 (gmt 0)

A flat file database is just like a csv file:

homer,safety tech,555-1234
lenny,operator,555-2222
moe,bar tender,555-1089

This is a file with data seperated by commas. The first column is name, then job, then phone number.

The main difference between that and say mysql is the way the file is read and the way it can link to other databases.

Basically, if you have simple data (like the above) then flat file is quick and easy.

You can use stuff like php or perl to read flat file data and they can quite easily handle thousands of records.

But if you are getting into more complex stuff such as relations e.g.

user database:
1,homer,safety tech,555-1234
2,lenny,operator,555-2222
3,moe,bar tender,555-1089

video rentals:
1,sleepless in seatle
1,dragnet
2,shaft
3,cocktail
3,debbie does springfield

Then flat files are too complicated and this stuff is ideal for something like mysql.

Spend some time googling out there for what you need. If you are sure that flat file is for you then you should find some old perl articles.

About 5 years ago I read some stuff on wdvl.com and how to use flat file database. The articles may still be there.

adb64




msg:1580400
 1:32 pm on Sep 30, 2005 (gmt 0)

If you want to use a CSV file for a flatfile database, this is easy to accomplish in PHP.
Use fopen [php.net] to open the file for reading or writing and then use fputcsv [php.net] to write a record to the file or fgetcsv [php.net] to read a record from the file.

Arjan

physics




msg:1580401
 8:24 pm on Sep 30, 2005 (gmt 0)

Learning how to make a simple database and do simple SQL queries with PHP will take about as much effort (or less) than learning how to 'roll your own' database program with flat files. And in the long run it'll prove much more useful to you.
Check out Chapter 7 of O'Reilly's 'Learning PHP 5'
That being said having a basic grasp of flat files is definitely a good idea. Usually you just have a CSV file or files, read it/them into arays, manipulate the data with your own functions, write the info back out. Pretty similar to using SQL execpt it's up to you to write the 'QL' (query language) instead of using the 'S' (standard) one ;)

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Databases
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved