Build Your Own Database 1

Build a Simple Flat File Database

Definiation of Database: "A structured set of data held in a computer, especially one that is accessible in various ways". (Lexico)

There must be infinite ways to organize, access and present data. Because I work with website applications, I chose to use text files as my database and PHP code to access and present the text as HTML.

The database is composed of text documents that reside in the 'data' folder in my application. Database: 'data folder'; Tables: sub-folders; Records: text documents inside sub-folders.

The following example, an online-magazine, illustrates the use of a text-file database with a single table, the 'stories' table, which is found in the 'data' folder of the application.

 text file database folders
The following file contains functions that convert text strings to associative arrays and back to strings to accomplish reading and writing operations. An associative array serves as a database record with named fields. A record key is a file name with the '.txt' characters removed.



Files and Folders for this demo:



top level file structure for SMALL1 application

'data' folder
data folder for the small2 demo website


'stories' folder


'pages' folder:


'admin-pages' folder


'inc' folder:


'index.php' file


Leave a comment


Previous comments


   2020-03-09

xxxxx