Each Database is represented by a Directory. A Database has
the same name as the Directory.
All Database-Directories have to be in the same Directory, and this Directory
(the one containing all Database Directories)
is set with the Setting $DB_DIR in the file txt-db-api.php.
Small Example:
$DB_DIR is set to "/home/websites/myhome/Databases/".
So you can have 1 or More Database (=> Database Folders) under /home/websites/myhome/Databases/.
If you want a Database called MyDb, it will be located in /home/websites/myhome/Databases/MyDb.
If you want a second Database called MySecondDB, it will be located in /home/websites/myhome/Databases/MySecondDB....
I recommend you to add a .htaccess File to each Database folder or the .txt
files in any folders that can be directly
read trough a browser (i.e. especially if the name is known).
$DB_DIR can also be set to a Windows Path of course, like C:\myWeb\bla\Databases\
Now if you want to execute a SQL-Statements on the Database
MyDb you have to
create a Database-Object first. For example:
$db=new Database("MyDb");
The argument in the constructor is the name (i.e. folder) of the database relative to the $DB_DIR directory.
ATTENTION: Database names are case sensitive
Now if you have a Database instance ($db) you can execute some
SQL Statements.
For example, to create a table :
$db->executeQuery("CREATE TABLE people (nr inc, name str, surname str, age int)");
You can also create Tables manualy.
Tables are stored as .txt Files in the Database Directory. But this is not so important, if you wish you can do everything with API calls without ever touching the .txt Files.
Only one thing is very important: All databases are really folders which must all be locatet in $DB_DIR!
IMPORTANT: The Database Directories must be create via FTP, and
do not forgett to do a chmod()
on the directory or the CREATE TABLE calls will fail!
Another example:
The Website-Root is under /home/website/myPage/
The API Files are under /home/website/myPage/txt-db-api/
The Directory containing the Databases is /home/website/myPage/Databases
Two Databases are installed named TestDB and ProdDB, therefore, the following directories exist:
/home/website/myPage/Databases/TestDB/
and
/home/website/myPage/Databases/ProdDB/
The rights to these folders where changed with chmod() (i.e. to 777 or something permitting write access).
For this Directory-Structures the Settings in the txt-db-api.php would look like this:
$API_HOME_DIR="/home/website/myPage/txt-db-api/"; $DB_DIR="/home/website/myPage/Databases/";
A php script in the Directory /home/website/myPage/ would start like:
<? php
include("txt-db-api/txt-db-api.php"); .....