drmvc / orm
Lightweight ORM
3.0.2
2018-04-18 16:00 UTC
Requires
- php: ^7.0
Requires (Dev)
- drmvc/config: ^3.0.0
- drmvc/database: ^3.0.0
- phpunit/phpunit: ~6.0
- zendframework/zend-coding-standard: ^1.0
Suggests
- ext-xdebug: ^2.6.0
This package is auto-updated.
Last update: 2024-10-29 04:59:01 UTC
README
DrMVC\Orm
Simple and easy-to-use lightweight ORM.
composer require drmvc/orm
Install
composer require drmvc/orm
How to use
<?php use DrMVC\Database; use DrMVC\Config; use DrMVC\Orm\Entity; use DrMVC\Orm\Orm; require_once __DIR__ . '/../vendor/autoload.php'; // Create config object and load database configuration $config = new Config(); $config->load(__DIR__ . '/config.php'); // Open connection with database $db = new Database($config); $instance = $db->getInstance(); $orm = new Orm('test_table', $instance); $entity = new Entity(); $entity->name = 'Kolya'; $entity->email = 'qweqwe'; $entity->password = 'qwerty3'; $orm->saveEntity($entity); // if find, update data if ($entity = $orm->findById(1)) { $entity->name = 'Pavel'; $entity->email = 'pavel@mail.ru'; $entity->password = 'qwerty3'; $orm->saveEntity($entity); } foreach ($orm->findAll() as $en) { echo '<pre>' . print_r($en->name . ' - ' . $en->id, true) . '</pre>'; echo '<pre>' . print_r($orm->deleteEntity($en), true) . '</pre>'; }