Get Started

Upgrade

Where Syntax

Query

Aggregation

Fetch

Transaction

Advanced

Raw object

PDO object

Debug

Information

version: 1.5.7

Collaboration with other frameworks

Medoo is friendly working with other frameworks together. You can register Medoo object via singleton extension that most of full-stack frameworks supported, and access back directly with the registered name. For more details, you can read about their official documentation about how to co-work with third-party library.

Laravel

Laravel provided singleton function to register a new singleton object. You can create and return the Medoo object there. The database configuration can be set on config file and load back via Config::get().

Registration on app.php
// Use Medoo namespace
use Medoo\Medoo;

// Register as database
$app->singleton('database', function () {
	return new Medoo([
		'database_type' => 'mysql',
		'database_name' => 'name',
		'server' => 'localhost',
		'username' => 'your_username',
		'password' => 'your_password'
	]);
});
Accessing Medoo

After registered via singleton, you can access the Medoo object via using $this->app->database, and started using any Medoo APIs.

Route::get('/', function () {

	$data = $this->app->database->select('account', ['id', 'name']);

	return json_encode($data);
});

Slim

You can create Medoo object to the app's container array, and you can access it via $this->database.

require './vendor/autoload.php';

use Medoo\Medoo;

$app = new \Slim\App();

$container = $app->getContainer();

$container['database'] = function () {
	return new Medoo([
		'database_type' => 'mysql',
		'database_name' => 'name',
		'server' => 'localhost',
		'username' => 'your_username',
		'password' => 'your_password'
	]); 
};

$app->get('/', function($request, $response, $args) {

	$data = $this->database->select('account', ['id', 'name']);

	return $response->write(json_encode($data));
});

$app->run();