1. Go to this page and download the library: Download almacil/php-database 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/ */
almacil / php-database example snippets
// Create instance
$db = new \Almacil\Database($database);
// Basic
$db->find($collection, /* function to find */);
$db->insert($collection, $item);
$db->update($collection, /* function to find */, $update);
$db->remove($collection, /* function to find */, $permanent);
// More
$db->count($collection, /* function to find */);
$db->findOne($collection, /* function to find */);
$db->upsert($collection, /* function to find */, $update);
$db->drop($collection);
$db->newid();
// Require composer autoloader
son files of databases
$database = __DIR__ . '/data';
// Create de instance
$db = new \Almacil\Database($database);
// "database/collection" or "collection" or "collection/subcollection"
$collection = 'mycollection/mysubcollection';
// ... after insert
$find = new stdClass();
$find->_id = $newItem->_id;
$items = $db->update($collection, function($item) use ($find) {
return $find->_id === $item->_id;
});
// ... after create instance $db
$item = new stdClass();
$item->name = 'Rubén';
$newItem = $db->insert($collection, $item);
// ... after insert
$find = new stdClass();
$find->_id = $newItem->_id;
$update = new stdClass();
$update->name = 'Rubén Pérez';
$numberItemsUpdated = $db->update($collection, function($item) use ($find) {
return $find->_id === $item->_id;
}, $update);
// ... after insert
$find = new stdClass();
$find->_id = $newItem->_id;
$permanent = true;
$numberItemsRemoved = $db->remove($collection, function($item) use ($find) {
return $find->_id === $item->_id;
}, $permanent);
bash
composer requiere almacil/php-database
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.