Initialize Medoo and perform basic CRUD operations
masterTo use Medoo, require the Composer autoloader, import the Medoo\Medoo namespace, and instantiate the Medoo class with your database configuration.
Supported database types include mysql, mariadb, pgsql, sqlite, mssql, oracle, and sybase.
Basic operations include:
insert($table, $data): Inserts data into a table.select($table, $columns, $where): Retrieves data from a table based on conditions.
// Load Composer's autoloader.
require 'vendor/autoload.php';
// Import the Medoo namespace.
use Medoo\Medoo;
// Create a database connection.
$database = new Medoo([
'type' => 'mysql',
'host' => 'localhost',
'database' => 'name',
'username' => 'your_username',
'password' => 'your_password'
]);
// Insert data.
$database->insert('account', [
'user_name' => 'foo',
'email' => 'foo@bar.com'
]);
// Retrieve data.
$data = $database->select('account', [
'user_name',
'email'
], [
'user_id' => 50
]);
echo json_encode($data);