PHP code example of amund / pdo-silo
1. Go to this page and download the library: Download amund/pdo-silo 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/ */
amund / pdo-silo example snippets
use Silo\Silo;
// 1. Connect and create tables
$pdo = new \PDO('mysql:host=localhost;dbname=mydb;charset=utf8', 'login', 'password');
$silo = new Silo($pdo, 'test');
$silo->create();
// 2. Create resources (returns their ids)
$john = $silo->set('person', ['firstname' => 'John', 'lastname' => 'Doe']);
$cynth = $silo->set('person', ['firstname' => 'Cynthia', 'lastname' => 'Doe']);
$regis = $silo->set('person', ['firstname' => 'Régis', 'lastname' => 'Doe']);
// $john = 1, $cynth = 2, $regis = 3
// 3. Read a resource
$silo->get($john);
// => ['id' => 1, 'class' => 'person', 'firstname' => 'John', 'lastname' => 'Doe']
// 4. Modify an attribute
$silo->setAttr($john, 'gender', 'M');
// 5. Link resources
$silo->link($john, $cynth, 'married_to');
$silo->link($regis, $john, 'son_of');
// 6. Read with links
$silo->get($john, links: true);
// => ['id' => 1, 'class' => 'person', ..., 'links' => [
// 'from' => ['married_to' => [2]], // people linked TO John
// 'to' => ['son_of' => [3]], // people John links TO
// ], 'lists' => [
// 'from' => [], // ordered lists John belongs to
// 'to' => [], // ordered lists John owns
// ]]
// 7. Search (accepts int values natively)
$silo->search(['where' => $silo->filter('age', '>=', 18)]);
$silo->search(['where' => $silo->filter('lastname', 'LIKE', '%Doe%')]);
// => ['total' => 3, 'results' => [1, 2, 3], 'duration' => '0.000123']
// 8. Ordered lists
$tagA = $silo->set('tag');
$tagB = $silo->set('tag');
$silo->setList($john, 'tags', [$tagA, $tagB]);
$silo->getList($john, 'tags'); // => [$tagA, $tagB]