1. Go to this page and download the library: Download ilias/maestro library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
ilias / maestro example snippets
use Ilias\Maestro\Database\Select;
use Ilias\Maestro\Database\Connection;
$select = new Select(Connection::get());
$select->from(['u' => 'users'], ['u.id', 'u.name'])
->where(['u.active' => true])
->order('u.name', 'ASC')
->limit(10);
$sql = $select->getSql();
$params = $select->getParameters();
use Ilias\Maestro\Database\Insert;
use Ilias\Maestro\Database\Connection;
use Maestro\Example\User;
$user = new User('John Doe', '[email protected]', md5('password'), true, new Timestamp('now'));
$insert = new Insert(Connection::get());
$insert->into(User::class)
->values($user)
->returning(['id']);
$sql = $insert->getSql();
$params = $insert->getParameters();
use Ilias\Maestro\Database\Update;
use Ilias\Maestro\Database\Connection;
$update = new Update(Connection::get());
$update->table('users')
->set('name', 'Jane Doe')
->where(['id' => 1]);
$sql = $update->getSql();
$params = $update->getParameters();
use Ilias\Maestro\Database\Delete;
use Ilias\Maestro\Database\Connection;
$delete = new Delete(Connection::get());
$delete->from('users')
->where(['id' => 1]);
$sql = $delete->getSql();
$params = $delete->getParameters();
namespace Maestro\Example;
use Ilias\Maestro\Abstract\Schema;
use Ilias\Maestro\Abstract\Table;
use Ilias\Maestro\Abstract\PostgresFunction;
use Ilias\Maestro\Types\Timestamp;
final class Hr extends Schema
{
public User $user;
}
final class User extends Table
{
public Hr $schema;
public string $username;
public string $email;
public string $password;
public Timestamp | PostgresFunction | string $createdIn = "CURRENT_TIMESTAMP";
public function compose(
string $username,
string $email,
string $password,
Timestamp $createdIn
) {
$this->username = $username;
$this->email = $email;
$this->password = $password;
$this->createdIn = $createdIn;
}
public static function tableUniqueColumns(): array
{
return ["username", "email"];
}
}
lias\Maestro\Database\DatabaseManager;
use Ilias\Maestro\Database\Connection;
use Maestro\Example\Hr;
use PDO;
// Initialize PDO with environment variables
$pdo = Connection::get();
// Initialize DatabaseManager
$dbManager = new DatabaseManager($pdo);
// Create schemas and tables based on the defined classes
$queries = $dbManager->createTablesForSchema(new Hr());
foreach ($queries as $query) {
$dbManager->executeQuery($pdo, $query);
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.