FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Flat file question





chrismen
I have set up a user system on my website using flat files and each line of the flat file contains a different value (ie. username, email, password, etc.). My question is what is the best way to do this (best = fastest load times pretty much)? Would it be better to use one flat file for all users or keep it how I have it. Also is there any big advantage with using databases like mysql bc I don't like those a lot.
hexkid
chrismen wrote:
I have set up a user system on my website using flat files and each line of the flat file contains a different value (ie. username, email, password, etc.). My question is what is the best way to do this (best = fastest load times pretty much)? Would it be better to use one flat file for all users or keep it how I have it. Also is there any big advantage with using databases like mysql bc I don't like those a lot.

Using a database is a whole lot better!

Now ... for multiple files (one for each user) or a single file (with all users in it). Each has its own advantages and disadvantages. The thing to consider is the opening and closing of the file(s): the less you open/close a file the better.

When working with one single user (validating, updating, getting info) it's better to have multiple files: you open one single file, and the data is ready to use. If you had one file with many users, you'd have to search the file for the specific user you're interested in.

When working with all users at the same time (find account by e-mail, count active users) a single file is better. You open and read it to process the data; you multiple files, you'd need to open each and every file.

With a database you can just as easily treat it specifically for a single user or as a group for the whole users.
AndreyL
I would recommend to use RDB (MySQL for example), it's easier and more secure than to use flat files. Flat files is rather insecure solution, so I wouldn't use it if you want to protect your information.
chrismen
Thanks for the info guys. I have done a lot to my flat files and think they are pretty secure. I cannot even think of a way people can get into them. Even if they do it is not that big of a deal - it is just for my users to login - no personal data or anything. The only reason I don't like databases like mysql is because I cannot as easily transfer them to anywhere I want and plus I need special programs to manually manipulate the files.
Esch
You should try out SQLite; it offers the convenience of flat files with some of the speed and integrity of a dedicated SQL database: http://us2.php.net/manual/en/ref.sqlite.php

Basically, you run your queries against a flat file that's loaded into memory and optimized like a real SQL database. If you need to move your project, you just copy the flat files along with the rest of it.

EDIT: (no pun intended) As far as editing the files goes, you can write scripts in PHP to help you do that management; true, it does take a bit more work than just throwing everything in some big file, but the forethought put into your database organization often makes the rest of your project much easier and more sensible.
NemoySpruce
If you are expecting to have more users I would use MySQL. A flat file can become cumbersome when it gets big, even if you distribute it to a lot of small files, its still a pain to maintain. But if its just a small site, and security is not that much of a concern, a flat file is OK. MySql data is easily portable using export feature.
chrismen
Okay thanks everyone. You've all convinced me. I will make a switch to sql during the weekend. Also, I will take Esch's idea of creating some php code to help me with the database. I hadn't thought of that before.
Related topics
Any flat file DBMS that is suitable for portable application
need help in a simple php register script based on flat file
SQLite
An ip 2 location system in design, interesting find
User Viewing A PHP File
Flat file-based, MySQL-based counter
Login Script
data extraction from dat flat file
News script
File "doesn't exist"
Which is your favourite weblog Script?
[GUIDE]Testing Out Your Site Without Uploading It
Help Needed Regarding CGI And Php
Dynamic User Customizable Sites. CSS + PHP = Awesome!
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.