Refactored the entire script into functions for everything.

This is a first step to turning the script into a class and before
it becomes version 5.4/5.5 compatible when I rename the project.

The script remains functionally the same as the original except it
can use either MySQL or SQLite and has an extra install() function
rather than test for the tables on every invocation. Use...

    tit.php?install=1

after editing the database settings at the top of the script to set
up either database from scratch.

Many thanks to Jwalanta Shrestha and friends for a great script :-)