PHP code example of devture / silex-provider-doctrine-mongodb

1. Go to this page and download the library: Download devture/silex-provider-doctrine-mongodb 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/ */

    

devture / silex-provider-doctrine-mongodb example snippets



// Register services under the 'mongodb' namespace, with no custom configuration (empty array)
$app->register(new \Devture\SilexProvider\DoctrineMongoDB\ServicesProvider('mongodb', []));

// Get a reference to a database on that server connection
$app['db'] = function ($app) {
	return $app['mongodb.connection']->selectDatabase('database_name');
};


// See the docs for \MongoClient (http://php.net/MongoClient) for connection string format and options
$configuration = [
	'server' => 'mongodb://example.com:27017',
	'options' => [
		'connect' => true,
		'connectTimeoutMS' => 200,
	],
];

$app->register(new \Devture\SilexProvider\DoctrineMongoDB\ServicesProvider('mongodb', $configuration));

$app['db_main'] = function ($app) {
	return $app['mongodb.connection']->selectDatabase('database_name');
};

$app['db_other'] = function ($app) {
	return $app['mongodb.connection']->selectDatabase('another_database_name');
};