mrmadclown / mnemosyne
Mnemosyne a PDO Database Layer
v1.3
2023-01-26 21:13 UTC
Requires
- php: ^8.1
- ext-pdo: *
- ext-pdo_mysql: *
Requires (Dev)
- infection/infection: 0.26.18
- phpunit/phpunit: 9.5.28
This package is auto-updated.
Last update: 2024-11-06 16:49:01 UTC
README
This is a simple PDO based mysql Query Builder
Installation
composer require mrmadclown/mnemosyne
Usage
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);
Important
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.