PHP code example of siriusphp / orm

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

    

siriusphp / orm example snippets


use Sirius\Orm\Orm;
use Sirius\Orm\ConnectionLocator;
$connectionLocator = ConnectionLocator::new(
    'mysql:host=localhost;dbname=testdb',
    'username',
    'password'
);
$orm = new Orm($connectionLocator);

$orm->register('pages', MapperConfig::fromArray([
    /**
     * here goes the configuration 
     */
]));

// continue with the rest of mappers

// find by ID
$page = $orm->find('pages', 1);
// or via the mapper
$page = $orm->get('pages')->find(1);

// query
$pages = $orm->select('pages')
             ->where('status', 'published')
             ->orderBy('date desc')
             ->limit(10)
             ->get();

// manipulate
$page->title = 'Best ORM evah!';
$page->featured_image->path = 'orm_schema.png';

// persist
$orm->save($page);
// or via the mapper
$orm->get('pages')->save($page);