Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Flat Text Database Scripts
08-09-2011, 12:51 PM,
Flat Text Database Scripts
Believe or not, there are still many hosting providers that does not allow their customers to run a MySQL database, whether cheap hosting or free hosting services, so people need to look at a simpler solution to cope with this limitation.

Some other people may prefer a flat database because is easier to connect and maintain, but whatever is the reason someone is using this type of text databases, it would be interesting to hear some opinions, not about how fast or convenient is MySQL in comparison, but what kind of flat database is better and more efficient.

Flat text writes on text files, as easy as that.
XML database does the same but over an XML-formatted DB
SQlite is a flat database engine that offers better security and performance

I think I'm missing some other options so I would really like to hear your input about these or any other non-MySQL databases that can be used as an alternative.
MyDigitalpoint PRO Freelance Marketplace
08-09-2011, 07:09 PM,
RE: Flat Text Database Scripts
Nice, but I'm a bit confuse, what is flat text files?
08-10-2011, 12:11 AM,
RE: Flat Text Database Scripts
It means text files without formatting or special coding to store information.

In example, if you want to log the IP your visitors come from, you can do it using this code:


$v_ip = $REMOTE_ADDR;
$v_date = date("l d F H:i:s");

$fp = fopen("visitors.txt", "a");
fputs($fp, "IP: $v_ip - DATE: $v_date\n\n");

In this example the flat text database is "visitors.txt," a simple empty file created with Notepad, uploaded to the server and chmode 666 or 777 on it to make it writable so the server can store the information writing down the IPs as plain text.

MyDigitalpoint PRO Freelance Marketplace
08-10-2011, 11:25 AM, (This post was last modified: 08-10-2011, 11:43 AM by RichardGv.)
RE: Flat Text Database Scripts
As far as you are going to do anything serious, I see almost no point to reject SQLite:
  • Why are RDBMS created? Well, the first issue it resolves is concurrent access. Think about the scenario when your site has 5 visitors sending a request simultaneously. 4 of them are trying to read your review about a movie, one person is trying to submit a new comment to your reviews. Since when writing to a flat file it has to be locked to avoid data corruption, the file is locked until the new comment is written to the file, so one person's access is causing latencies for 4 persons. When your sites have, let's say, 100 concurrent requests, flat files would be a total disaster.
  • Permissions. Flat files lack the extensive permission control RDBMS offers, important for large projects.
  • It's hard to provide random access to flat files. Well, it is not entirely impossible to do it yourself, yet it adds much complexity.
  • PHP is an interpreted language, which means, well, it's generally slow. An benchmark showed Python is 3 times faster than PHP, and Java/C++ are roughly 100x faster than Python. (Of course, no general comparison can be done.) It is very unlikely that a PHP script parsing a flat text file could be faster than SQLite, written in C.
  • You may have to convert numbers or other kinds of special data back or to their text representation. Performance penalty.
  • As for XML, it's good for extensibility (yeah, where the "X" comes from), yet bad as a database format. It uses tons of unnecessary tags, does not support random access, and cannot store binary data efficiently, even worse than normal flat files. Also, if you use a DOM-tree XML parser, it would put the entire XML file in memory, thus you would probably need to pay 3 additional bucks a month to add more memory to your VPS. soon
  • Since SQLite uses SQL, it requires less code changes later to move your site to a MySQL/PostgreSQL/MsSQL environment once your site grows larger.
  • Writing a database engine yourself would take a lot of time, and certainly SQLite would be more bug-free than yours, so why bother reinventing the wheels? And there are already tons of tools that enables you to view (graphically) and edit SQLite databases.

However, for simple one-user scripts or a PHP engine with no SQLite support, flat files remain a viable choice, and certain scripts indeed support it.
Gentoo Linux User (w/ fvwm) / Loyal Firefox User / Owner of a Stupid Old Computer - My PGP Public Key

No man is an island, entire of itself; every man is a piece of the continent, a part of the main; if a clod be washed away by the sea, Europe is the less, as well as if a promontory were, as well as if a manor of thy friends or of thine own were; any man's death diminishes me, because I am involved in mankind; and therefore never send to know for whom the bell tolls; it tolls for thee.
-- Devotions Upon Emergent Occasions (1624), John Donn
08-10-2011, 12:36 PM,
RE: Flat Text Database Scripts
I use flat files if I am too lazy to make a new table or am only writing something for temporary use. The affiliate script on NiftyHost used to use flat files, but switched to MySQL when loading 4000+ IP addresses and running an explode() and a foreach loop on the resulting array on every referral started to be an issue.
Hi! I'm Zach, and I founded NiftyHost. If you need anything, just PM me! :)
07-26-2012, 06:57 PM,
RE: Flat Text Database Scripts
Might not be so bad for a simple blogging script with occasional updates, but not a very good solution for long term. I would never try and run a forum, for example, on a flat file database.
07-26-2012, 09:57 PM,
RE: Flat Text Database Scripts
I'm using flat files on a wiki.

So if you want a wiki without a DB use DokuWiki :).

Forum Jump: