1.1.1 Query builders update
Select
The Select
class allows you to build and execute SELECT queries.
use Ilias\Maestro\Database\Select;
use Ilias\Maestro\Database\PDOConnection;
$select = new Select(PDOConnection::getInstance());
$select->from(['u' => 'users'], ['u.id', 'u.name'])
->where(['u.active' => true])
->order('u.name', 'ASC')
->limit(10);
$sql = $select->getSql();
$params = $select->getParameters();
Insert
The Insert
class allows you to build and execute INSERT queries.
use Ilias\Maestro\Database\Insert;
use Ilias\Maestro\Database\PDOConnection;
use Maestro\Example\User;
$user = new User('John Doe', 'john@example.com', md5('password'), true, new Timestamp('now'));
$insert = new Insert(PDOConnection::getInstance());
$insert->into(User::class)
->values($user)
->returning(['id']);
$sql = $insert->getSql();
$params = $insert->getParameters();
Update
The Update
class allows you to build and execute UPDATE queries.
use Ilias\Maestro\Database\Update;
use Ilias\Maestro\Database\PDOConnection;
$update = new Update(PDOConnection::getInstance());
$update->table('users')
->set('name', 'Jane Doe')
->where(['id' => 1]);
$sql = $update->getSql();
$params = $update->getParameters();
Delete
The Delete
class allows you to build and execute DELETE queries.
use Ilias\Maestro\Database\Delete;
use Ilias\Maestro\Database\PDOConnection;
$delete = new Delete(PDOConnection::getInstance());
$delete->from('users')
->where(['id' => 1]);
$sql = $delete->getSql();
$params = $delete->getParameters();