PHP code example of bixev / light-orm

1. Go to this page and download the library: Download bixev/light-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/ */

    

bixev / light-orm example snippets





\Bixev\ORM\API::setDatabaseGetter(function($databaseName){
    $db = new \PDO('');
    return $db;
});

$exampleRepository = \Bixev\ORM\API::get('Example');

$example = $exampleRepository->createNew();
// same as
// $example = new \Bixev\ORM\Example();
$example->example_2_id = 5;
$example->name = "Tom";
$example->save();
echo $example->getId();

$id = 3;
$example = $exampleRepository->find($id);
// same as
// $example = new \Bixev\ORM\Example($id);
echo $example->name;

$db = new \PDO('');
$row = $db->query("SELECT id, name, example_2_id FROM user")->fetch();
// row has to contain all declared fields
$user = new \Bixev\ORM\Example($row);

$examples = $exampleRepository->findBy(['name' => "Tom"]);
$examples = $exampleRepository->findAll();
foreach ($examples as $example) {
    echo $example->name;
}

$db = new \PDO('');
$rows = $db->query("SELECT id, name, example_2_id FROM user")->fetchAll();
// rows have to contain all declared fields
$examples = $exampleRepository->newCollection($rows);

$example = $exampleRepository->findOneBy(['name' => "Tom"]);