Get Started

Upgrade

Where Syntax

Query

Aggregation

Fetch

Transaction

Management

Advanced

Raw object

PDO object

Debug

Information

version: 2.1.7

What is New v2.1

Bug fixes, better support for Oracle and the performance is slightly improved.

Raw for BETWEEN

$this->database->select("account", "user_name", [
	"birthday[<>]" => [
		Medoo::raw("to_date(:from, 'YYYY-MM-DD')", [":from" => '2015/05/15']),
		Medoo::raw("to_date(:to, 'YYYY-MM-DD')", [":to" => '2025/05/15'])
	]
]);
SELECT "user_name"
FROM "account"
WHERE
("birthday" BETWEEN to_date('2015/05/15', 'YYYY-MM-DD') AND to_date('2025/05/15', 'YYYY-MM-DD'))

LOBs for Oracle

Better support for inserting and updating LOBs for the Oracle database.

$fp = fopen('foo.dat', 'r');

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

$database->update("ACCOUNT", [
	"DATA" => $fp
], [
	"ID" => 1
]);

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).

// 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"
]);