Get Started

Upgrade

Where Syntax

Query

Aggregation

Fetch

Transaction

Advanced

Raw object

PDO object

Debug

Information

version: 1.6

What's New v1.6

Improved initialization

Medoo 1.6 is now supported more connection options, and allowed passing PDO object for initialization. Check out more detail from https://medoo.in/api/new

$database = new Medoo([
	// required
	'database_type' => 'mysql',
	'database_name' => 'name',
	'server' => 'localhost',
	'username' => 'your_username',
	'password' => 'your_password',

	// [optional]
	'collation' => 'utf8mb4_general_ci',

	// [optional] The application name for MSSQL
	'appname' => 'test',

	// [optional] MSSQL connection options
	'application_intent' => 'ReadOnly',
	'attach_db_file_name' => './database.sql',
	....
]);
$pdo = new PDO('mysql:dbname=test;host=127.0.0.1', 'user', 'password');

$database = new Medoo([
	// Initialized and connected PDO object
	'pdo' => $pdo,

	// [optional] Medoo will have different handle method according to different database type
	'database_type' => 'mysql'
]);

Better error output

try {
	$database = new Medoo([
		'database_type' => 'mysql',
		'database_name' => 'name',
		'server' => 'localhost',
		'username' => 'your_username',
		'password' => 'your_password',
	]);
}
catch (Exception $e) {
	echo $e->getMessage();
}

// Will output: Incorrect connection options

New rand() API

Medoo provided a new way for getting randomized data. It's also compatible with other database.

$data = $database->rand("account", [
	"user_name",
	"email"
], [
	"user_id[>]" => 100
]);

Output DSN String for info()

info() will output the DSN string now. You can check out this for debug database connection.

print_r($database->info());

/*
Array
(
	[server] => Uptime: 5000  Threads: 1  Questions: 15  Slow queries: 0  Opens: 67  Flush tables: 1
		Open tables: 60  Queries per second avg: 0.002
	[client] => mysqlnd 5.0.10 - 20111026 - $Id: a707c415db32080b3752b232487a435ee0372157 $
	[driver] => mysql
	[version] => 5.6.10
	[connection] => localhost via TCP/IP
	[dsn] => mysql:dbname=test;host=127.0.0.1
)
*/

Improvements

Bug Fixed