fordnox / mikron
PDO 对象映射器
1.3
2014-06-08 15:01 UTC
Requires
- php: >=5.3
Requires (Dev)
- phpunit/phpunit: 4.1.1
This package is not auto-updated.
Last update: 2024-09-24 01:46:16 UTC
README
简单的PHP PDO数据映射器
将数据库行映射到简单的PHP对象,没有更多。
用法
将数据库值加载到订单对象中。类所有公共成员必须与数据库中的字段名相同。实体通过“id”字段识别
简单模型类
class Entity { /** @field */ public $id; /** @field */ public $name; /** Not a field */ public $anything; }
将数据库值映射到实体类
$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
自定义实体名称和表名称
定义自定义函数将实体映射到表名称,反之亦然。默认情况下,实体名称与表名称相同。
$this->mikron->setNameResolver(function($type, $name) { return ucfirst($name); });