Skip to content

Medoo v1.6

Compare
Choose a tag to compare
@catfan catfan released this 08 Oct 07:20
· 218 commits to master since this release

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'
]);
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

  • Call aggregate methods without magic call
  • get() returns NULL instead of False if find nothing
  • Handle MariaDB as same as MySQL
  • Code simplified and improved performance

Bug Fixed

  • Match keyword is only supported for MySQL
  • Execute special command for customized DSN connection