Get Started

Medoo 1.4

Where Syntax

Query

Fetch

Transaction

Advanced

PDO object

Debug

Information

version: 1.4.3

Upgrading to Medoo 1.4

Medoo 1.4 have a lot of incompatible changes with older version. If you want to upgrade Medoo to this version, please read the following guide.

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.2+
$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.2+
$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.4
$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.4
$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