NiftyHost Forums (Archive)
Flat Text Database Scripts - Printable Version

+- NiftyHost Forums (Archive) (https://niftyhost.chary.us/support)
+-- Forum: Webmaster Zone (https://niftyhost.chary.us/support/forum-38.html)
+--- Forum: Site Software (https://niftyhost.chary.us/support/forum-39.html)
+--- Thread: Flat Text Database Scripts (/thread-1321.html)



Flat Text Database Scripts - MyDigitalpoint - 08-09-2011

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.


RE: Flat Text Database Scripts - zZJoennZz - 08-09-2011

Nice, but I'm a bit confuse, what is flat text files?


RE: Flat Text Database Scripts - MyDigitalpoint - 08-10-2011

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:

Code:
<?php

$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");
fclose($fp);
?>


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.






RE: Flat Text Database Scripts - RichardGv - 08-10-2011

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.


RE: Flat Text Database Scripts - Zach - 08-10-2011

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.


RE: Flat Text Database Scripts - OhioTom76 - 07-26-2012

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.


RE: Flat Text Database Scripts - Serial Thrilla - 07-26-2012

I'm using flat files on a wiki.

http://wiki.singul4rity.com

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