Get Started

Upgrade

Where Syntax

Query

Aggregation

Fetch

Transaction

Advanced

Raw object

PDO object

Debug

Information

version: 1.6

From v1.5 to v1.6

get() will return null instead of false

Medoo 1.6 will return null if find nothing.

Old version
$email = $database->get("account", "email", [
	"user_id" => 1234
]);

echo $email;
// Will output: false
Medoo 1.6+
$email = $database->get("account", "email", [
	"user_id" => 1234
]);

echo $email;
// Will output: null

From v1.4 to v1.5

Using SQL functions

Medoo 1.5 is now using raw object for complex query. The old version `#` is not supported anymore. It's much more powerful.

Old version
$database->insert("account", [
	"user_name" => "bar",
	"#uid" => "UUID()"
]);
Medoo 1.5+
$database->insert("account", [
	"user_name" => "bar",
	"uid" => Medoo::raw("UUID()")
]);

MSSQL connection

Medoo 1.5 will use pdo_sqlsrv drvier for MSSQL database connection with all platform by default, because Microsoft released new pdo_sqlsrv driver for both Linux and Windows platform. If you want to use old version dblib driver, you can specify driver option with dblib value for using this drvier.

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

	// [optional] If you want to force Medoo to use dblib driver for connecting MSSQL database
	'driver' => 'dblib'
]);

From older version to v1.5

Installation

Medoo is now dropped support for PHP 5.1. The minimize environment is now required PHP 5.4+ since 1.2+.

Initialization

Medoo is now using namespace and PSR standard. You have to add use Medoo\Medoo; in front of the initialization, and change new medoo() to new Medoo()

Old version
require 'vendor/autoload.php';

$database = new medoo([
	'database_type' => 'mysql',
	'database_name' => 'name',
	'server' => 'localhost',
	'username' => 'your_username',
	'password' => 'your_password',
]);
Medoo 1.2+
require 'vendor/autoload.php';

use Medoo\Medoo;

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

Last insert ID

For old version, the API insert() will return the last inserted row ID by default. But for Medoo 1.2, you have to call the new API id() alone to get the ID.

Old version
$account_id = $database->insert("account", [
	"user_name" => "foo",
	"email" => "foo@bar.com",
	"age" => 25
]);
Medoo 1.5
$database->insert("account", [
	"user_name" => "foo",
	"email" => "foo@bar.com",
	"age" => 25
]);

$account_id = $database->id();

New API

Medoo updated all API method name to camel case, and simplified the name.

Old version
$database->insert("account", [
	"user_name" => "foo",
	"email" => "foo@bar.com",
	"age" => 25
]);

$database->last_query();
Medoo 1.5
$database->insert("account", [
	"user_name" => "foo",
	"email" => "foo@bar.com",
	"age" => 25
]);

$database->last();

JSON declaration

Medoo is supported type declaration since 1.4, and unified all type declaration symbol as [type]. So the old version JSON declaration for insert() and update() have to update for the upgrade.

Old version
$database->insert("account", [
	"user_name" => "foo",
	"email" => "foo@bar.com",
	"age" => 25,
	"(JSON) lang" => ["en", "fr", "jp", "cn"]
]);

$database->update("account", [
	"user_name" => "foo",
	"email" => "foo@bar.com",
	"age" => 25,
	"(JSON) lang" => ["en", "fr", "jp", "cn"]
], [
	"user_id" => 50
]);
Medoo 1.5
$database->insert("account", [
	"user_name" => "foo",
	"email" => "foo@bar.com",
	"age" => 25,
	"lang [JSON]" => ["en", "fr", "jp", "cn"]
]);

$database->update("account", [
	"user_name" => "foo",
	"email" => "foo@bar.com",
	"age" => 25,
	"lang [JSON]" => ["en", "fr", "jp", "cn"]
], [
	"user_id" => 50
]);

Update, Insert and Delete return result

update(), insert()anddelete()method will return the PDO::Statement object instead of number of affected row since 1.4. You can call its method for more special usage.

Old version
$query = $database->insert("account", [
	"user_name" => "foo",
	"email" => "foo@bar.com",
	"age" => 25,
	"(JSON) lang" => ["en", "fr", "jp", "cn"]
]);

echo $query; // The number of affected row
Medoo 1.5
$query = $database->insert("account", [
	"user_name" => "foo",
	"email" => "foo@bar.com",
	"age" => 25,
	"lang [JSON]" => ["en", "fr", "jp", "cn"]
]);

echo $query->rowCount(); // The number of affected row
echo $query->errorInfo(); // Fetch extended error information for this query

// Read more: http://php.net/manual/en/class.pdostatement.php