Top Related Projects
Quick Overview
Medoo is a lightweight PHP database abstraction layer that simplifies database operations. It supports multiple database types, including MySQL, MSSQL, SQLite, and PostgreSQL, and provides a clean, easy-to-use API for performing common database tasks.
Pros
- Simple and intuitive API for database operations
- Supports multiple database types with a unified interface
- Lightweight and fast performance
- Prepared statements for enhanced security
Cons
- Limited advanced features compared to full-fledged ORMs
- May not be suitable for complex database operations
- Documentation could be more comprehensive
- Limited community support compared to larger frameworks
Code Examples
- Connecting to a database:
use Medoo\Medoo;
$database = new Medoo([
'type' => 'mysql',
'host' => 'localhost',
'database' => 'my_database',
'username' => 'root',
'password' => 'secret'
]);
- Inserting data:
$database->insert('users', [
'name' => 'John Doe',
'email' => 'john@example.com',
'age' => 30
]);
- Selecting data:
$users = $database->select('users', [
'name',
'email'
], [
'age[>]' => 25
]);
- Updating data:
$database->update('users', [
'age[+]' => 1
], [
'id' => 1
]);
Getting Started
- Install Medoo using Composer:
composer require catfan/medoo
- Include Medoo in your PHP file:
require 'vendor/autoload.php';
use Medoo\Medoo;
$database = new Medoo([
'type' => 'mysql',
'host' => 'localhost',
'database' => 'your_database',
'username' => 'your_username',
'password' => 'your_password'
]);
- Start using Medoo to perform database operations:
$data = $database->select('table_name', '*');
Competitor Comparisons
Doctrine Database Abstraction Layer
Pros of DBAL
- More comprehensive and feature-rich database abstraction layer
- Supports a wider range of database systems and advanced SQL features
- Part of the larger Doctrine ecosystem, offering integration with other Doctrine components
Cons of DBAL
- Steeper learning curve due to its complexity and extensive feature set
- Heavier and may introduce more overhead for simpler database operations
- Requires more configuration and setup compared to Medoo's simplicity
Code Comparison
Medoo:
$database = new Medoo([
'database_type' => 'mysql',
'database_name' => 'name',
'server' => 'localhost',
'username' => 'your_username',
'password' => 'your_password'
]);
$data = $database->select('table', ['column1', 'column2'], ['id' => 1]);
DBAL:
$connectionParams = [
'dbname' => 'mydb',
'user' => 'user',
'password' => 'secret',
'host' => 'localhost',
'driver' => 'pdo_mysql',
];
$conn = DriverManager::getConnection($connectionParams);
$queryBuilder = $conn->createQueryBuilder();
$result = $queryBuilder
->select('column1', 'column2')
->from('table')
->where('id = :id')
->setParameter('id', 1)
->executeQuery()
->fetchAllAssociative();
A lightweight nearly-zero-configuration object-relational mapper and fluent query builder for PHP5.
Pros of Idiorm
- Lightweight and simple to use, with a minimal learning curve
- Supports method chaining for more readable query construction
- Flexible and allows for raw SQL queries when needed
Cons of Idiorm
- Less feature-rich compared to Medoo, lacking advanced functionalities
- Not actively maintained, with the last update in 2015
- Limited database support (primarily MySQL, SQLite, and PostgreSQL)
Code Comparison
Medoo:
$data = $database->select("users", [
"name",
"email"
], [
"age[>]" => 18
]);
Idiorm:
$users = ORM::for_table('users')
->select(['name', 'email'])
->where_gt('age', 18)
->find_many();
Key Differences
- Syntax: Medoo uses array-based syntax, while Idiorm uses method chaining
- Maintenance: Medoo is actively maintained, Idiorm is not
- Features: Medoo offers more advanced features and wider database support
- Learning curve: Idiorm may be easier for beginners due to its simplicity
Conclusion
While Idiorm offers simplicity and ease of use, Medoo provides a more comprehensive solution with active development and broader database support. The choice between the two depends on project requirements and developer preferences.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
The lightweight PHP database framework to accelerate development.
Features
-
Lightweight - Portable with only one file.
-
Easy - Easy to learn and use, with a friendly construction.
-
Powerful - Supports various common and complex SQL queries, data mapping and prevents SQL injection.
-
Compatible - Supports MySQL, MSSQL, SQLite, MariaDB, PostgreSQL, Sybase, Oracle, and more.
-
Friendly - Works well with every PHP framework, such as Laravel, Codeigniter, Yii, Slim, and frameworks that support singleton extension or composer.
-
Free - Under the MIT license, you can use it anywhere, for whatever purpose.
Requirements
- PHP 7.3+
- Installed PDO extension
Get Started
Install via composer
Add Medoo to the composer.json
configuration file.
$ composer require catfan/medoo
And update the composer
$ composer update
// Require Composer's autoloader.
require 'vendor/autoload.php';
// Use the Medoo namespace.
use Medoo\Medoo;
// Connect to the database.
$database = new Medoo([
'type' => 'mysql',
'host' => 'localhost',
'database' => 'name',
'username' => 'your_username',
'password' => 'your_password'
]);
$database->insert('account', [
'user_name' => 'foo',
'email' => 'foo@bar.com'
]);
$data = $database->select('account', [
'user_name',
'email'
], [
'user_id' => 50
]);
echo json_encode($data);
// [{
// "user_name" : "foo",
// "email" : "foo@bar.com",
// }]
Contribution Guidelines
Before starting a new pull request, please ensure compatibility with other databases and write unit tests whenever possible.
Run phpunit tests
for unit testing and php-cs-fixer fix
to fix code style.
Each commit should start with a tag indicating the type of change: [fix]
, [feature]
, or [update]
.
Please keep it simple and keep it clear.
License
Medoo is released under the MIT license.
Links
-
Official website: https://medoo.in
-
Documentation: https://medoo.in/doc
-
Twitter: https://twitter.com/MedooPHP
-
Open Collective: https://opencollective.com/medoo
Support Our Other Product
Top Related Projects
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot