1. Go to this page and download the library: Download pyrsmk/olive 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/ */
pyrsmk / olive example snippets
// Create a connection to a database on localhost using default 27017 port
$olive=new Olive\Mongodb('my_database', array(
'username' => 'root',
'password' => 'blahblahblah'
));
// Create a connection to mongodb.example.com:67095 (you can easily add more hosts if you want)
$olive=new Olive\Mongodb('my_database', array(
'username' => 'root',
'password' => 'blahblahblah',
'hosts' => array(
'mongodb.example.com' => 67095
)
));
// Create a connection on localhost ('host' option is optional)
$olive=new Olive\Mysql('my_database', array(
'username' => 'root',
'password' => 'blahblahblah',
'host' => 'localhost'
));
// Create a simple connection with SQLite3
$olive=new Olive\Sqlite('path/to/database.db');
// Create a connection with SQLite2
$olive=new Olive\Sqlite('path/to/database.db', array(
'sqlite2' => true
));
$olive = new Olive\MariaDB('my_database', $options);
// Get the users table
$container = $olive->users;
$container = $olive['some_weird#table;name'];
$container = $olive->my_app_users;
// Set the global namespace
$olive->setNamespace('my_app_');
// Get the global namespace
$olive->getNamespace();
$ids = array(14, 51, 20, 18);
// Search for articles with an ID that is not in the $ids array
$olive->articles
->search('_id', 'not in', $ids)
->fetch();
// Get all articles
$olive->articles
->search()
->fetch();
// Get the title of the article with the 72 ID
$title=$olive->articles
->search('_id', 'is', 72)
->select('title')
->fetchFirst();
// Get articles written by '@pyrsmk'
$olive->articles->find('author_id', 'is', '@pyrsmk');
// Get one article
$olive->articles->findOne('_id', 'is', 10);
// Get the first field of the requested article
$olive->articles->findFirst('_id', 'is', 10);
// Let's get admins less older than 50 yo
$title=$olive->members
->search('group', 'is', 'admins')
->search('age', 'less', '50')
->fetch();
// Get title, text, author and date fields
$article = $olive->articles
->search('_id', 'is', 72)
->select('title')
->select('text')
->select('author')
->select('date')
->fetchOne();
// The second parameter of select() is the alias
$item = $olive->items
->search('iditem', 'is', 72)
->select('iditem', '_id')
->select('text', 'french')
->select('title', 'h1')
->fetchOne();
// Get articles from two weeks ago, with the author name
$olive->articles
->search('date', 'greater', time() - 1209600)
->join('articles.author_id', 'members.id')
->select('title')
->select('text')
->select('date')
->select('members.name', 'author')
->fetch();
class MyUsersModel extends Olive\Model{
// 'singular' and 'plural' properties are used in calls (see the method below)
protected $singular='user';
protected $plural='users';
// Define the data container name (AKA table or collection name)
protected $data_container='users';
// Define the primary key name
protected $primary_key='_id';
}
// Remove any user with their email and name fields set to '[email protected]' and 'Thomas' respectively
$userModel->removeUsers(array(
'email' => '[email protected]',
'name' => 'Thomas'
));
// Get an user with the following fields : '_id', 'email', 'date' (alias of 'user_creation') and 'text' (alias of 'profile_text')
$userModel->getUser($id,array(
'_id',
'email',
'user_creation' => 'date'
'profile_text' => 'text'
));
// Get table/collection names
$names = $olive->getDataContainerNames();
// Get database object (like PDO, MongoClient, ...)
$driver = $olive->getDriver();
// Verify adapter support
if(Olive\Mysql::isSupported()) {
// MySQL is currently supported in the PHP environment
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.