PLDBService
it's the main class that provides functionality for database management.
$pldb = new PLDBService();
Function returns the array that consists of databases names.
array<string> PLDBService::getDatabasesNames()
$databasesNames = $pldb->getDatabasesNames();
print_r($databasesNames);
Function requires a database name and returns the Database
instance.
Database PLDBService::selectDatabase($name)
$name = "foo-db";
$database = $pldb->selectDatabase($name);
Function requires a Database
instance.
boolean PLDBService::insertDatabase($database)
$pldb->insertDatabase($database);
Function requires a database name and returns the Database
instance.
After function call the database will be created and written to file.
Also it will be added to databases array in PLDB
instance.
Database PLDBService::createDatabase($name)
$name = "foo-db";
$database = $pldb->createDatabase($name);
After function call the database will be deleted from databases array and folder.
boolean PLDBService::dropDatabase($name)
$name = "foo-db";
$pldb->dropDatabase($name);
Function requires a database file path and returns the Database
instance.
After loading, database will be added to databases array.
Database PLDBService::loadDatabase($path)
$path = "db/foo-db";
$database = $pldb->loadDatabase($path);
Function requires a Database
instance.
After function call the database file will be created in databases folder.
Do not forget to save databases after changing them.
void PLDBService::saveDatabase($database)
$pldb->saveDatabase($database);
Database
class provides a table management.
Function requires a database name and returns the Database
instance.
Database will not be added to PLDBService
instanse instead of PLDBService::createDatabase
function.
$name = "foo-db";
$database = new Database($name);
Function returns the array that consists of tables names.
array<string> Database::getTablesNames()
$tablesNames = $database->getTablesNames();
print_r($tablesNames);
Function requires a table name and returns the Table
instance.
Table Database::selectTable($name)
$name = 'users';
$table = $database->selectTable($name);
Function requires a Table
instance.
boolean Database::insertTable($table)
$database->insertTable($table);
Function requires a table name and returns the Table
instance.
After function call the table will be created and added to the tables list in database.
The scheme
it's a key-value array that contains names of fields and their types (JSON Types).
Do not add an id
field to scheme, because it will be added later automatically.
Table Database::createTable($name, $scheme)
$name = "users";
$scheme = array(
"name" => "text",
"age" => "number",
);
$table = $database->createTable($name, $scheme);
After function call the table will be deleted from database tables array.
boolean Database::dropTable($name)
$name = "users";
$database->dropTable($name);
Function returs the name of database.
string Database::getName()
$name = $database->getName();
echo $name;
Table
class allows to work with the table data.
Function requires a table name and scheme, and returns the Table
instance.
Table will not be added to Database
instanse instead of Database::createTable
.
$name = "users";
$scheme = array(
"name" => "text",
"age" => "number",
);
$table = new Table($name, $scheme);
Function requires a condition and returns the array of Entry
instanses.
The condition
it's a key-value array that contains fields and their values.
array<Entry> Table::select($condition)
$condition = array(
"name" => "John",
);
$data = $table->select($condition);
print_r($data);
Function requires an object that will be converted to Entry and added to the entries array.
Feel free to pass to the function both an object and an array. The object firstly will be converted to array and then to Entry
.
void Table::insert($object)
$object = Array(
"name" => "John",
"age" => 27,
);
$table->insert($object);
Function requires an object that contains an entry id.
If there is no id in object the data will not be updated.
boolean Table::update($object)
$object = Array(
"id" => 0,
"name" => "John",
"age" => 27,
);
$table->update($object);
Function requires a condition.
Only the first found entry will be deleted.
void Table::delete($condition)
$condition = array(
"name" => "John",
);
$table->delete($condition);
Function returs the name of table.
string Table::getName()
$name = $table->getName();
echo $name;
Entry
class makes it easier to work with data in table.
Function returns the key-value array with the data.
array<string, string> Entry::getData()
$data = $entry->getData();
print_r($data);
DATABASE_EXISTS = "Database already exists!"
NO_DATABASE_FOUND = "There is no such database!"
TABLE_EXISTS = "Table already exists!"
NO_TABLE_FOUND = "There is no such table!"
CANNOT_OPEN_FILE = "Cannot open file!"