This is a simple PDO based mysql Query Builder
composer require mrmadclown/mnemosyne
The Builder gets constructed by passing an instance of the PDO::class
to
the \MrMadClown\Mnemosyne\Builder::class
use \PDO;
$pdo = new \PDO();
$builder = new \MrMadClown\Mnemosyne\Builder($pdo);
With the Builder Object a mysql query can be build similar to how a query would be written:
...
$builder->select('*')->from('users')->where('id', 1);
By default, the PDO Fetch Mode is set to PDO::FETCH_CLASS | PDO::FETCH_PROPS_LATE;
which means you have to have a
class which represents your table
#User.php
class User {
public int $id;
public string $name;
}
$builder->setClassName(User::class)->fetchAll(); // returns an array of Users
you can use the magic __set
method to map your database columns into your model.
If you don`t want a different FetchMode you can call $builder->setFetchMode(\PDO::FETCH_ASSOC)
to change the fetch mode of the Builder instance.