Best method for flatfile databases

Joined
Dec 17, 2008
Messages
210
Reaction score
31
I am starting a new project when I finish my current, and I have some plans, now what would be the best flatfile database method? I am familiar with MS-INI configuration file, used em and it was pretty simple, quite limited though when using the parse_ini_file method, text files and directories are useful, but lets say I wrote a CMS and 700 members registered, HDD overload or wut (:)), so, what would be the best method?


I dislike SQLite, so dont even think about it!
 
Well flat-file databases are pretty generic, yet differ quite a bit from one another.

CSV is a popular way. Basically, you have to choose a couple delimiters (one for columns (Ex: ","), another for rows (Ex: "\n"), figure a way to set column names and types, have a way to sort by different columns, possibly some built in security, etc.

You might start with a folder with the name of the database. Then you can have either a multi-dimensional flat-file DB with folders, or just all the files in there.

You need to build a parser in whatever language will work for the application, but you MUST use generic functions for insert, update, sort, delete (for rows), create, alter, move, drop, or rename (for files/folders). If you do this custom each time or use different functions for different files it's not going to be very customizable. I'd let the delimiter be set inside each file, Ex: the first line can set the delimiters, after that you can set the columns, and then start inserting rows.

Select functions must be able to select a given amount of rows based on how they're sorted, what values they have, and of course, what file/folders are associated with it. Consider being able to dynamically join different files/folders of rows and select/sort through data from multiple files.

Ex: If Author is a row in each of the files: "comments, profiles, blogs", then you might want to grab all of that data where "Author" value is for example, "Craig". Consider conditional arguments. (For example: 'Column "Author" is ("Craig" or "Jeff")' ). Also some functionality for conditions based on multiple columns is essential.

For all of this functionality, you might as well create a parser for a query language. . For Example:
Code:
Use myDB.blog, myDB.comments, myDB.profiles where Column "Author" is ("Craig" or Jeff") and Column "Active" is (1) and Sort("Date", descending)

Idk... What's wrong with MySQL/MsSQL or pre-built flat file DBs already out there?
 
I seriously don't see why you wouldn't use a SQL database, don't see how a flatfile database would be better in any way, but if you have to use it (even though it's way more work and harder to make/maintain) then I would suggest you check out how other public flatfile databases work, and then copy em etc to see what way works out best.
 
Use binary files if you dislike SQL (which is the dumbest thing I've heard, especially when you say "I dont know why I dont like it.. I just dont.").

With binary files (.dat), you can store data as (basic) types (byte, short, int, string, etc). The output data will be in binary, so it can be read faster. Most "flatfile" (not even the correct name) just parse strings, which takes alot of time.
 
Last edited:
I dont know why I dont like it.. I just dont.

I wrote a PHP class once to get and edit ms-ini variables, it didnt work so well with sections though...

SQL is good to get used to. There's more good reasons than not to use some sort of SQL db to write your own custom applications. Most SQL databases offer a secure way for PHP (and other languages) to send, receive, and manipulate data. Also, it's more developer friendly since pretty much all web developers know how to use at least one SQL database.

Sometimes it's fun to write your own languages, but usually not for practical use- more for learning experiences. Occasionally, BB-code and the-like are useful for user-generated content without the risk (if done right) of XSS injections. I wrote my own BB-code parser because there was a lack of functionality in the free ones available.

If you think there's a lack of functionality in MySQL (or whatever SQL DB), there's a possibility you're not aware of certain things your chosen DB could do. Parameterized Queries, JOIN statements, builtin function/statements (LIKE, NOW(), DATESUM(), etc) make MySQL very customizable. MSSQL is arguably better at some things, MySQL better at other. There's other ones to look into as well.

But again, if you looked into doing something but ran into a road block, post what you're trying to do and there's probably a good way to do it with MySQL.
 
Back