Skip to content

MrMadClown/mnemosyne

Folders and files

NameName
Last commit message
Last commit date
Jan 26, 2023
Jan 26, 2023
Jan 26, 2023
Aug 27, 2022
Aug 27, 2022
Aug 27, 2022
Jan 26, 2023
May 11, 2023
May 11, 2023
Jan 26, 2023
Aug 27, 2022
Aug 27, 2022

Repository files navigation

Mnemosyne - a PDO Database Layer

License: MIT Latest Stable Version Total Downloads example workflow example workflow

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.