Medoo 助力开发的轻量级数据库框架

为什么选择 Medoo

  • 轻量级
    小于100kb,仅有一个文件。

  • 简单
    非常容易学习和使用,友好的框架

  • 强大
    支持各种常见和复杂的SQL查询,数据映射以及防止SQL注入

  • 兼容
    支持所有SQL数据库,包括MySQL,MSSQL,SQLite,MariaDB,PostgreSQL,Sybase,Oracle等

  • 友好
    适用于所有PHP框架,如Laravel,Codeigniter,Yii,Slim和支持单例扩展或composer的框架

  • 免费
    MIT 协议, 你可以进行任何修改。

使用步骤

要求

  • PHP>=5.4, 必须支持PDO.
  • 支持 MySQL, MSSQL, SQLite 等数据库.
  • 确保php_pdo_xxx (xxx = 数据库类型) 的xxx数据扩展已经正确安装并启用.
  • 需要懂一些SQL知识.

composer 依赖安装

1
$ composer require catfan/Medoo

更新

1
$ composer update

开始使用

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// If you installed via composer, just use this code to require autoloader on the top of your projects.
require 'vendor/autoload.php';

// Using Medoo namespace
use Medoo\Medoo;

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

// Enjoy
$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"
// }
// ]

文档地址

Medoo