Skip to content

The Next-Gen v2.0

Compare
Choose a tag to compare
@catfan catfan released this 28 Apr 08:38
· 77 commits to master since this release

What is New v2.0

The milestone version of Medoo. We have updated the whole project with more standard and reliable code, including some new features and significant improvements. We also updated and redesigned the official documentation website.

Error initialization option

The new error option to indicate how to handle error information.

$database = new Medoo([
	// Can be set as PDO::ERRMODE_SILENT, PDO::ERRMODE_WARNING, PDO::ERRMODE_EXCEPTION
	// Default is PDO::ERRMODE_SILENT
	'error' => PDO::ERRMODE_SILENT
]);

Simplified connection options

Those option names are simplified (you can still use the old one of course).

  • database_type -> type
  • database_name -> database
  • server -> host
// New
$database = new Medoo([
	'type' => 'mysql',
	'host' => 'localhost',
	'database' => 'name',
	'username' => 'your_username',
	'password' => 'your_password',
]);

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

New callback closure for select()

The high-performance way to output data immediately without loading it into memory.

$database->select("account", ["name"], function ($data) {
	echo $data["name"];
});

New way to getting result from action()

To get the result from action(), you can provide the reference variable with the use keyword for the closure and then get it back from outside.

$result = "";

$database->action(function($database) use (&$result) {

	$database->insert("account", [
		"user_name" => "foo"
	]);

	$newId = $database->id();

	$result = "The account is created, id is {$newId}.";
});

echo $result;

New way to get the error information

The function $database->error() is removed. Just read the $database->error or $database->errorInfo to get the error information last performed.

$database->insert("account", [
	"user_name" => "foo"
]);

var_dump($database->error);
var_dump($database->errorInfo);

Last inserted id on Oracle

If want to the last inserted id on Oracle, provide the primary key as third parameter for insert() and get it from id().

$database->insert("ACCOUNT", ["NAME" => "foo"], "ID");

var_dump($database->id());

Debug Logging

To debug the whole or the part of your project without putting debug() to every call, you can use beginDebug() to start debug logging, and then call debugLog() to stop it and get all debug logs as an array.

// Begin debug logging
$database->beginDebug();

// All those functions will not be executed but will save it as a debug log.
$database->select()......
$database->update().....

// Call debugLog() to stop debug logging and return all debug logs as an array.
var_dump($database->debugLog());

// Will output:
// array(2) {
//  [0]=> string(10) "SELECT ... FROM"
//  [1]=> string(10) "UPDATE ... SET ... WHERE ..."
// }

Join with Raw Object and Additional Condition

$database->select("post", [
	"[>]comment" => [
		"author_id" => "user_id",
		"AND" => [
			"rate[>]" => 50
		]
	],
	"[>]account" => Medoo::raw("ON <post.author_id> = <account.user_id>")
], [
	"post.content",
	"comment.content",
	"account.name"
]);
  • PSR-2 standard.
  • Test cases included.
  • PHPDoc comments included.
  • Drop support for PHP 5.4, the minimal requirement is PHP 7.3+.
  • Better support for MSSQL and Oracle.
  • Supports using Unicode character as table/column name.
  • The official documentation website https://medoo.in is redesigned.

Enjoy it! :)