PHP code example of drmvc / orm

1. Go to this page and download the library: Download drmvc/orm library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

drmvc / orm example snippets





use DrMVC\Database;
use DrMVC\Config;
use DrMVC\Orm\Entity;
use DrMVC\Orm\Orm;

g->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 = '[email protected]';
    $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>';
}