# Managing data
# DB Connector
The most basic way to manipulate data from the database is using the DBConnector class, this can be useful in some simple case, but avoid using it on complex projects.
use mays\core\DBConnector;
// getting data with executeSelect, where the result is an array of objects
$com = "SELECT tenant_id FROM ay_user WHERE id = ?";
$res = DBConnector::executeSelect($com, [$id]);
//manipulate data with the executeQuery
$com = "UPDATE ay_user SET email = ? WHERE id = ?";
$res = DBConnector::executeSelect($com, [$email, $id]);
# Mays Wrapper
A single class to manipulate any objects in a more object-oriented style. This sould be the best way to use on websites, since it optimized to work with Mays Web Template Boilerplate.
use mays\wrapper\MaysWrapper;
use mays\wrapper\Filter;
/*
Client is the Schema name and id is a field (check schemas and fields
documentation if you have any doubt). If you don't send any filter on
the second argument you will get all objects from the Client schema.
*/
$schema = new MaysWrapper();
/*
by default you don't need to say the language you want because
it will be used the default one, or if you are using MaysWrapper
with the Mays Web Template Boilerplate it will use the active
language on the website.
*/
$schema->setLanguage($lang);
$client = $schema->selectSchemaContent('Client', [new Filter("id", "=", $id)]);
//you also have functions to insert, update or delete data
$schema->insertIntoSchema("Client", ["name" => $name]);
$schema->updateIntoSchema("Client", $id, ["name" => $name]);
$schema->deleteFromSchema("Client", $id);
# Semantic approach
This is probably the most intuitive way to deal with data, since we can use classes with the real schema names, making code more legible. In order to make this works a classe with the same name of the schema must exists under mays\core\schema. By default this directory only brings some system schema that need specific code like Tokens. The following code would be enough to work with the Form Schema.
namespace mays\core\schema;
use mays\core\schema\GenericSchema;
class Form extends GenericSchema
{
public function __construct() {
$this->schemaName = "Form";
}
}
This means we can now use code like this.
use mays\core\schema\Form;
$form = new Form();
$the_form = $form->get($id);
echo $the_form->any_prop_from_form;
This classes must extends GenericSchema and we can use useful methods like:
- getAll($colums = [], $skip_meta = false)
- filterBy($filters, $colums = [], $skip_meta = false)
- getFirst($filters, $colums = [], $skip_meta = false)
- insert($values)
- update($id, $values)
- getParent($id)
- getAllChilds($childSchemaName, $id)
All get methods have 2 optional arguments that allow you to get only specific columns of schema instead the entire set of columns, and another to remove meta and audit fields from the result. By default all columns including audit and meta data will be returned.
A full list of other methods can be found on the GenericSchema classe. If you want to know more about the power of the semantic schema classes please check the next section, the events.