Website Services

Online Magazine with Flat File Database

For our second example, we are going to create an online magazine.

The magazine will be coded in PHP and the database will consist of 3 arrays: 2 tw-dimensional array: 'stories' and 'authors' and a one-dimensional array tags. As in the first example, commas are used to delimit the one-dimensional array and 3-character strings are used to delimit the two-dimensional arrays. These arrays are all stored as text files, with 'stories' and 'authors' inside folders, while the tags are a single text file.

Section 1: Defining the Database:



This file defines the field delimiter and record fields:

This folder holds the 'author' records:
CATSTACK/data/authorsfolder-icon

This folder holds the 'stories' records:
CATSTACK/data/storiesfolder-icon

This file contains a list of 'tags':


Section 2: Relationships between records

As in Example 1, relationships between tables are established by 'maps' - two-dimensional arrays containing pairs of values.
The 'story-author' map:

The 'date-story' map:

The 'tag-story' map:


Section 3: Accessing Records and Maps

The 'functions' file is the database management system. This file contains code for reading and writing the records and arrays, and querying the database.

For example, to find all the stories by an author, you would use the 'selectMapEntries' function and specify the 'story-author' map and the author record id. By leaving the story record variable emtpy, all the stories by the author will be returned in an array.

The home page queries the database using 2 maps - the date-story map, the story-author map and the tag-story map:


The 'display-tag' page queries the database using the tag-story map: