CREATE TABLE SuperDBHistory (
h_table varchar(64) NOT NULL default '',
h_date datetime NOT NULL default '0000-00-00 00:00:00',
h_user varchar(16) NOT NULL default '',
h_event varchar(255) NOT NULL default '',
h_ip varchar(16) NOT NULL default ''
);
CREATE TABLE Metainformation (
mi_table varchar(64) NOT NULL default '',
mi_created datetime NOT NULL default '0000-00-00 00:00:00',
mi_creator varchar(16) NOT NULL default '',
mi_modified datetime NOT NULL default '0000-00-00 00:00:00',
mi_modifier varchar(16) NOT NULL default '',
mi_user_IP text NOT NULL,
mi_admin_IP text NOT NULL,
mi_html_header text NOT NULL,
mi_fields text NOT NULL,
mi_database_name varchar(255) NOT NULL default '',
mi_table_name varchar(255) NOT NULL default '',
mi_per_page int(11) unsigned NOT NULL default '50',
mi_admins text NOT NULL,
mi_foreign_keys text NOT NULL,
mi_usermaydelete enum('0','1') NOT NULL default '0',
PRIMARY KEY (mi_table)
);
Then create a separate user to access this database. That's all.
Generally you want all your scripts to share the same database to
store phpSuperDB setup.
<?
require_once("superdb.lib.php");
new SuperDB ("localhost","SuperDB","superdb","34534password234234",
"localhost","Documents","Mail");
SuperDB::start_engine();
?>
The first row represents access parameters to your meta database.
The second row - hostname, database name, table name.
General table setup:
In this case the script when given empty parameters will take the real one from the
first object created. The class constructor automatically creates and fills global array
of object references. When multiple tables are used the default screen will be selecting
table and the new menu button will appear to select table. Current table index is
stored in session.
It is all obvious. An empty any of first six parameters will make use of first created object.
Empty
The last parameter specifies that
The only parameter defines index of table which will be used by default.
Table setup
After the first user logs in engine automatically creates new record
in Metainformation table that will hold all setup.
There are two kinds of users: users and admins. By default all are admins.
Admins are granted special abilities: edit table setup, view history and
depending on setup deletion of rows in database.
Field setup:
if certain IP is present in admin IP's list it needs not to be present in user IP's list
if you add some IP into either list the script will automatically make sure that your current IP address will be listed too
Multiple tables
There is a nice solution to edit several tables in one database using one script instead of creating multiple scripts.
Example:
<?
require_once("superdb.lib.php");
new SuperDB ("localhost","SuperDB","superdb","1234password123123",
"localhost","SomeDatabase","FirstTable");
new SuperDB ("","","","","","","SecondTable");
new SuperDB ("","","","","","","ThirsTable");
new SuperDB ("","","","","","","FourthTable");
SuperDB::start_engine();
?>
Documentation
Class constructor:
Method
<?
function SuperDB ($metahost,$metadatabase,$metausername,$metapassword,
$host,$database,$table,$tableuniquename="",$lang="en");
?>
$tableuniquename will default to $table.
superdb.lang.en.php file will be included
in the same directory where superdb.php script resides. To make it in your own
language just copy this file to superdb.lang.something.php and edit it, then
use "something" as the last parameter.
start_engine();:
<?
function start_engine($defaultindex=0);
?>
API
With phpSuperDB you can use the following features.
If function
superdb_get_username_password() is present, it will be automatically used to retrieve username and password.
It must return array($username, $password).
If function
save_field_FieldName_hook($value) is present, it has to return SQL code in form "FieldName='Value'".
Example:
<?
function save_field_password_hook($value)
{
if (preg_match("/^[abcdef\d]{16}$/",$value))
return "password='$value'";
else
return "password=PASSWORD('".mysql_escape_string($value)."')";
}
?>
TODO