Build Your Own Database 2

Flat file database with three tables

A second table, 'writers' has been added to the database along with 'stories'. Each story record contains a foreign key, 'writer' that points to the 'writers' table.



However, there can be multiple stories for each writer. To manage this many-to-one relationship, a third table is needed. I use an array as a 'map' to hold pairs of record keys. If more tables are added to the database, more maps can be created to join them.

An addional set of database functions is used to access these map arrays:


Files and Folders for this demo:

top level file structure for SMALL2 application

'data' folder

data folder for the small2 demo website


'writers' folder


'stories'folder


'pages' folder:


'admin-pages' folder


'inc' folder:


'index.php' file


Leave a comment