Lila Avenue

Website Projects

Flat File Relational Database Example 1

For our first example, we are going to create a personal account management program.

The program will be coded in PHP and the database will consist of 2 arrays: a one-dimensional array for 'categories' and a two-dimentsional array for 'accounts'.

The 'categories' array is delimited by commas, while the two-dimensional array uses 3-character delimiters. The 'categories' array is stored as a text file and the 'accounts' array is stored as multiple text files within an 'accounts' folder.



The 'database-definitions' file defines the delimiters and the structure of the two-dimensional 'accounts' arrays.

This folder holds the 'account' records:
ACCOUNTS/data/accountsfolder-icon



This file contains a list of 'categories':


Section 2: Relationships between records

Relationships between tables are established by 'maps' - two-dimensional arrays containing pairs of values. The 'category-account' 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 the category-account map. Accounts associated with each category are listed, and if there are no relationships found, the account is listed as 'Uncategorized.'