Entry
How can I use plain txt files instead of a database for a backend of a site, ie managing news posts, uploading files, message boards etc...
Feb 18th, 2008 19:35
dman, Dave Kingdon, Jared Mackenzie, http://www.ttnr.org
The key to this problem can be summed up in one word: encoding.
Due to the fact that the structure of the database is also in the
medium, you have to make sure that you set rules for the structure of
the file, and then adhere to them in the entire site (otherwise you're
just making the database flawed, possibly terminally).
Depending on how advanced you are, you could start (quite simply) by
using a tab-delimited text file for posts:
<id>[ tab ]<name>[ tab ]<email>[ tab ]<homepage>
So the data file would look like:
0 Dave Kingdon dave@joliet.co.uk http://lsyg.com
1 Someone Else dunno@whatever.com http://pmoj.com
Then, you can use that along with a file for postings:
<id>[ tab ]<p_id>[ tab ]<subject>[ tab ]<date>
0 0 Demonstration file 2021-03-27
1 0 Demonstration file 2 2021-03-27
So you can see from files 1 & 2 that both posts were posted by me.
Now, to make your database driven site a bit quicker, you should make
yourself some functions (preferrably in an include file for ease) that
can mimic SQL server functions (in ability as opposed to syntax - I
take it you're not Stephen Hawking), so you can use other people's
ideas and pseudocode in developing something really cool.
As for binary files, you can use the built-in base64 encoding function
(I think I saw one somewhere) to encode binary into text for storage
(it might be a good idea to put 1 binary file into its own text file so
it doesn't interfere with your database/text-file layout, and assign it
its own ID so you can refer to it in your tables).
It may sound daunting, but keep at it.
Dave