Flat-File Database-
The flat-file style of database are
ideal for small amounts of data that needs to be human readable or edited by
hand. Essentially all they are made up of is a set of strings in one or more
files that can be parsed to get the information they store; great for storing
simple lists and data values, but can get complicated when you try to replicate
more complex data structures. That's not to say that it is impossible to store
complex data in a flat-file database; just that doing so can be more costly in
time and processing power compared to a relational database. The methods used
for storing the more complex data types, are also likely to render the file
unreadable and un-editable to anyone looking after the database.
The typical flat-file database is
split up using a common delimiter. If the data is simple enough, this could be
a comma, but more complex strings are usually split up using tabs, new lines or
a combination of characters not likely to be found in the record itself.
One of the main problems with using
flat files for even a semi-active database is the fact that it is very prone to
corruption. There is no inherent locking mechanism that detects when a file is
being used or modified, and so this has to be done on the script level. Even if
care is taken to lock and unlock the file on each access, a busy script can
cause a "race condition" and it is possible for a file to be wiped
clean by two or more processes that are fighting for the lock; the timing of
your file locks will become more and more important as a site gets busy.
Database
Management (DBM) Layer
The Database Management Layer allows
script programmers to store information as a pair of strings; a key, which is
used to find the associated value. Essentially, a DBM adds more functionality
and better sortation during storage to the binary flat-files that it uses.
There are several versions of DBMs available, but the most popular is the
Berkley Database Manager; also known as the Berkley DB.
The Berkley DB is an improvement over
normal flat-files, as it provides a way for programmers to use the database
without having to worry about how the data is stored or how to retrieve the
values. Retrieval of data using the Berkley DB is often much faster than from a
flat-file, with the time savings being made by storing data in a way that
speeds up the locating of a specific key-value pair.
Creating, editing and deleting data
when using the Berkley DB is actually quite simple; once the database has been
tied to the script you just use and manipulate the variables as normal. The
problem of file locking that plagues flat-file databases is still apparent when
using DBM, so you should still take care when planning scripts that utilize it..