SkayoDB


> What is SkayoDB?

SkayoDB is a Flat-File-Database System I wrote.
It uses XML for storing data and .htaccess to deny access from anyone. So it's save too!
SkayoDB is free and easy to use and for everyone who don't want to spend money on a MySQL-Server like me.

> Installation

To install SkayoDB just paste the code below in a PHP-Script in the directory you like to install and run it once.
Everything will be installed automatically.

<?php
ini_set('user_agent','Mozilla/4.0 (compatible; MSIE 6.0)');
file_put_contents('SkayoDB.php', file_get_contents('http://skayo.lima-city.de/tests/SkayoDB/SkayoDBxml.txt'));
require_once('SkayoDB.php');
$db = new SkayoDB;
echo $db->setup();
?>

To use it after installation just use

require_once('SkayoDB.php');
$db = new SkayoDB;

at the beginning of your code.
And if you dont knew already, you can then access the functions with

$db-><function>(<parameter>);

> Config

In the SkayoDB-File is a little config array.
Here is a short explanation of the values:

debug

Setting debug to true will return all errors.
At default, debug is True.

DB_dir

If the path is not DB you can set this to where the DB-Directory is.
So for example if you want the DB-Directory to be data/DB/, you set the path to data/DB.

> Functions

There are 5 availablecommands. Here is a short explanation of the functions:

createDB(name)

Used to create a Databank.

Parameter:
name
The name of the database you want to create.

newXMLelement(DBname, content, elementname, parent, parentnum, attributename, attributevalue)

Used to create a new XML-Node.

Parameter:
DBname
The name of the database you want to use.
content
The content you want to store in that node.
elementname
The name of the node you want to create.
parent
The name of the parent wich you want to create a child from.
parentnum
If you have more than one parent of a name, you can choose the number of the parent you want to use.
attributename
The name of the attribute, if you want to have an attribute for the node.
attributevalue
The value of the attribute, if you want to have an attribute for the node.

updateXMLvalue(DBname, newValue, elementname, elementnum)

Used to update the value of an existing node.

Parameter:
DBname
The name of the database you want to use.
newValue
The new value you want to store.
elementname
The name of the node you want to update.
elementnum
If you have more than one nodes of a name, you can choose the number of the node you want to update.

getXML(DBname, mode, elementname, elementnum, attributename, attributevalue)

Used to get the value of an existing node.

Parameter:
DBname
The name of the database you want to use.
mode
The mode you want to use. You can choose between value (to get the value), number (to get the number of an node) and count (to get the number of existing nodes)
elementname
The name of the node you want to get the information from.
elementnum
If you have more than one nodes of a name, you can choose the number of the node you want to get the information from.
attributename
The name of the attribute you want to get the value from.
attributevalue
The value of the attribute you want to get the value from.

removeXMLnode(DBname, parentname, parentnum, elementname, elementnum)

Used to remove an existing node.

Parameter:
DBname
The name of the database you want to use.
parentname
The name of the parent you want to delete a child from.
parentnum
The number of the parent you want to delete a child from.
elementname
The name of the node you want to delete.
elementnum
The number of the node you want to delete.

> Example

Here is an complete example of how to use SkayoDB for storing the age of a user:

First we make sure we are able to use SkayoDB:

require_once('SkayoDB.php');
$db = new SkayoDB;

Then we create our database named userdata :

$db->createDB('userdata');

This will make a file named userdata.xml in the DB-Directory wich contains the following:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<databank>
    <userdata>
    </userdata>
</databank>

Then we create a parent node with the attribute username="Skayo" as a child of userdata :

$db->newXMLelement('userdata', '', 'user', 'userdata', 0, 'username', 'Skayo');

Now our XML-File contains the following:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<databank>
    <userdata>
    <user username="Skayo"></user> </userdata>
</databank>

Then we create the child node wich is storing the age of the user as a child of user :

$db->newXMLelement('userdata', '14', 'age', 'user');

Now our XML-File contains the following:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<databank>
    <userdata>
    <user username="Skayo"><age>14</age><user></userdata>
</databank>

And now we want to output our age:

echo $db->getXML('userdata', 'value', 'age'); // This will output 14

Cool! Then, for example a year has passed an we want to update our age. Then we use this:

$db->updateXMLvalue('userdata', '15', 'age');

Now our XML-File contains the following:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<databank>
    <userdata>
    <user username="Skayo"><age>15</age><user></userdata>
</databank>

Awesome! And then, for example our user is dead and we want to delete his data. Then we use this:

$db->removeXMLnode('userdata', 'userdata', 0, 'user');

Now our XML-File contains the following:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<databank>
    <userdata>
    </userdata>
</databank>

That's it! Here is the entire example-code again:

require_once('SkayoDB.php');
$db = new SkayoDB;
$db->createDB('userdata');
$db->newXMLelement('userdata', '', 'user', 'userdata', 0, 'username', 'Skayo');
$db->newXMLelement('userdata', '14', 'age', 'user');
echo $db->getXML('userdata', 'value', 'age');
$db->updateXMLvalue('userdata', '15', 'age');
$db->removeXMLnode('userdata', 'userdata', 0, 'user');

If you have any questions, just ask me via Twitter: @Skayo_.