PDO to object mapper

1.3 2014-06-08 15:01 UTC

This package is not auto-updated.

Last update: 2024-04-08 23:45:12 UTC


Build Status

Simple PHP PDO data mapper

Maps database rows to simple PHP object and nothing more.


Load database values to Order object. All public members of the class must be the same as field names in database. Entity is identified by field "id"

Simple model class:

    class Entity
        /** @field */
        public $id;

        /** @field */
        public $name;

        /** Not a field */
        public $anything;

Maps database values to Entity class

    $mikron = new Mikron(new Pdo(...));
    $entity = $mikron->load('entity', 1);
    print $entity->id;
    print $entity->name;

    $entity->name = 'New Name';
    $mikron->store($entity); //updates entity name in DB

Custom entity names and table names

Define custom function to map entities to table names and vice versa. By default entity name is same as table name.

    $this->mikron->setNameResolver(function($type, $name) { return ucfirst($name); });