Get Started

Medoo 1.4

Where Syntax





PDO object



version: 1.4.5

Get Started

Using Medoo is extremely easy!



On PHP 5.4+, you can use [] as short array syntax. All Medoo example code are using [] instead of array().

// On PHP 5.1
$data = array("foo", "bar");

// On PHP 5.4+
$data = ["foo", "bar"];

PHP_PDO extension list

PHP PDO driver installation

Medoo is requiring PHP with PDO supported. If you didn't install before, follow this step.

// Open php.ini and remove the ';' for the database extension you want to install.

// .dll is for Windows and .so for Linux/UNIX

// From

// To

// Save it, and restart PHP or Apache server.

// If PDO is installed successfully, you can find it on phpinfo().

Or install via terminal. The PDO_XXX extension will be enabled and configured automatically.

$ sudo apt-get install php5-mysql

Composer Installation

If you know about composer, it is easy to install and manage the version dependence. Just use this command to add Medoo to composer.json. Or you can edit it depend on your requirement.

$ composer require catfan/Medoo

And update the composer

$ composer update

Download Installation

The most simple way. Just download medoo.php and put it into the right directory and then require, and now you are ready!

require  'medoo.php';


There are three ways to configure Medoo and start a database connection.

// If you installed via composer, just use this code to requrie autoloader on the top of your projects.
require 'vendor/autoload.php';

// Using Medoo namespace
use Medoo\Medoo;

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

	// [optional]
	'charset' => 'utf8',
	'port' => 3306,

	// [optional] Table prefix
	'prefix' => 'PREFIX_',

	// [optional] Enable logging (Logging is disabled by default for better performance)
	'logging' => true,

	// [optional] MySQL socket (shouldn't be used with server and port)
	'socket' => '/tmp/mysql.sock',

	// [optional] driver_option for connection, read more from
	'option' => [

	// [optional] Medoo will execute those commands after connected to the database for initialization
	'command' => [

$database->insert("account", [
	"user_name" => "foo",
	"email" => ""

Customized DSN Connection

You can also use customized DSN to connect the database that Medoo didn't supported by default, especially for some new database requiring special DSN parameter for database connection, or if you want to add more DSN parameters value for connection than original one.

The format of DSN connection string:
$database = new Medoo([
	// Started using customized DSN connection
	'dsn' => [
		// The PDO driver name for DSN driver parameter
		'driver' => 'mydb',
		// The parameters with key and value for DSN
		'server' => '',
		'port' => '8886'
	// [optional] Medoo will have different handle method according to different database type
	'database_type' => 'mysql',

	'username' => 'your_username',
	'password' => 'your_password'

// The final DSN connection string will be generated like this


If you want to use MSSQL with Medoo under PHP platform, you need to install pdo_sqlsrv PHP extension for Windows or pdo_dblib for Linux/UNIX. pdo_mssql extension is deprecated and will be removed from PHP.

For SQLite

$database = new Medoo([
	'database_type' => 'sqlite',
	'database_file' => 'my/database/path/database.db'

$database->insert("account", [
	"user_name" => "foo",
	"email" => ""