PHPackages                             tjn/mpdo - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. tjn/mpdo

ActiveLibrary[Database &amp; ORM](/categories/database)

tjn/mpdo
========

pdo

v1.3.1(3y ago)011PHPPHP &gt;=7.3

Since Aug 4Pushed 3y ago1 watchersCompare

[ Source](https://github.com/tangccy/mpdo)[ Packagist](https://packagist.org/packages/tjn/mpdo)[ RSS](/packages/tjn-mpdo/feed)WikiDiscussions master Synced 6d ago

READMEChangelogDependenciesVersions (6)Used By (0)

pdo简易封装
=======

[](#pdo简易封装)

实例化
---

[](#实例化)

```
$config = [
    'dbms' => 'mysql',
    'host' => '127.0.0.1',
    'port' => '3306',
    'dbname' => 'learn01',
    'user' => 'root',
    'password' => '123456',
];
$pdo = PdoClient::connect($config);
```

表
-

[](#表)

### table()

[](#table)

```
//plat_user是表名
$pdo->table('plat_user');
```

条件
--

[](#条件)

#### where()

[](#where)

参数会形成AND组合

```
//1.二维数组 sql:select * from `plat_user` where (actor=1 and status=0)
$pdo->table('plat_user')
    ->where([
        ['actor', '=', 1],
        ['status', '=', 0]
    ]);

//2.一维数组 sql:select * from `plat_user` where (actor=1)
$pdo->table('plat_user')
    ->where(['actor', '=', 1]);

//3.分开传参 sql:select * from `plat_user` where (actor=1)
$pdo->table('plat_user')
    ->where('actor', '=', 1);
```

#### whereOr()

[](#whereor)

参数会形成OR组合

```
//1. sql:select * from `plat_user` where (actor=1 or status=0)
$pdo->table('plat_user')
    ->whereOr([
        ['actor', '=', 1],
        ['status', '=', 0]
    ]);
```

#### whereIn()

[](#wherein)

```
//1.三维数组传参 sql:select * from `plat_user` where (actor in (1,2,3) and status in(0,1))
$pdo->table('plat_user')
    ->whereIn([
        ['actor', [1,2,3]],
        ['status', [0,1]]
    ]);

//2.二维数组传参 sql:select * from `plat_user` where (actor in (1,2,3))
$pdo->table('plat_user')
    ->whereIn(['actor', [1,2,3]]);

//2分开参数传参 sql:select * from `plat_user` where (actor in (1,2,3))
$pdo->table('plat_user')
    ->whereIn('actor', [1,2,3]);
```

#### whereInOr()

[](#whereinor)

```
//1.三维数组传参 sql:select * from `plat_user` where (actor in (1,2,3) OR status in (0,1))
$pdo->table('plat_user')
    ->whereIn([
        ['actor', [1,2,3]],
        ['status', [0,1]]
    ]);
```

#### whereNotIn()

[](#wherenotin)

```
//1.三维数组传参 sql:select * from `plat_user` where (actor not in (1,2,3) AND status not in (0,1))
$pdo->table('plat_user')
    ->whereNotIn([
        ['actor', [1,2,3]],
        ['status', [0,1]]
    ]);

//2.二维数组传参 sql:select * from `plat_user` where (actor not in (1,2,3))
$pdo->table('plat_user')
    ->whereNotIn(['actor', [1,2,3]]);

//3.分开参数传参 sql:select * from `plat_user` where (actor not in (1,2,3))
$pdo->table('plat_user')
    ->whereNotIn('actor', [1,2,3]);
```

#### whereNotInOr()

[](#wherenotinor)

```
//1.三维数组传参 sql:select * from `plat_user` where (actor not in (1,2,3) OR status not in (0,1))
$pdo->table('plat_user')
    ->whereNotInOr([
        ['actor', [1,2,3]],
        ['status', [0,1]]
    ]);
```

#### whereRaw()

[](#whereraw)

```
//1.三维数组传参 sql:select * from `plat_user` where (actor=1 and status=0)
$pdo->table('plat_user')
    ->whereRaw('actor=? and status=?', [1, 0]);
```

获取数据
----

[](#获取数据)

### get()

[](#get)

```
//1.sql:select * from `plat_user` where (actor=1 and status=0)  这里只是将组装的预处理sql用execute执行，并且返回 PDOStatement结构的数据
$pdo->table('plat_user')
    ->whereRaw('actor=? and status=?', [1, 0])
    ->get();
```

### first()

[](#first)

```
//1.在get()的基础上fetch取出一条数据
$pdo->table('plat_user')
    ->whereRaw('actor=? and status=?', [1, 0])
    ->first();
```

### all()

[](#all)

```
//1.在get()的基础上fetchAll取出全部数据
$pdo->table('plat_user')
    ->whereRaw('actor=? and status=?', [1, 0])
    ->all();
```

### count()

[](#count)

```
//1.sql:select count(`id`) total from `plat_user` where (actor=1 and status=0) 但是count方法会直接返回int统计数
$pdo->table('plat_user')
    ->whereRaw('actor=? and status=?', [1, 0])
    ->count();
```

### groupBy

[](#groupby)

```
//1.sql:select * from `plat_user` where (status=0) group by actor
$pdo->table('plat_user')
    ->where('status', 0)
    ->groupBy('actor')
    ->all();
```

### orderBy

[](#orderby)

```
//1.sql:select * from `plat_user` where (status=0) order by id desc
$pdo->table('plat_user')
    ->where('status', 0)
    ->orderBy('id desc')
    ->all();
```

### join

[](#join)

```
$pdo->table('plat_user', 'u')
    ->join('plat_config_detail as p', 'u.id=p.upUser')
    ->join('plat_actor as m', 'm.id=u.actor', 'LEFT')
    ->limit(0, 20)
    ->field('u.id, u.account, p.upUser, p.configId, u.actor, m.name as actor_name')
    ->all();
```

插入数据
----

[](#插入数据)

### insert()

[](#insert)

```
//数据
$data = [
    'id'=>1,
    'account'    => 'xiaoming',
    'name'   => 'ming',
    'real_name'  => '小名',
    'password'   => '8ef7d5456ebff0b52316376c7649670d',
    'phone'   => '13800138000',
    'area' => 0,
    'actor' => 1,
    'permission' => '{"10000":["exchangerefund","phprun","buserinfo","operalog","catVerCode","channelconf","approveOper","approveLogs","approveApply","approveConfig"],"9999":["buserinfo","exchangerefund","phprun","exchangeship","applySend","catVerCode","actorAdmin","editAdmin","menuAdmin","area","confManager","robot"],"1":[]}',
    'status' => 2,
    'gameids' => '',
];
//返回的是ID
$id = $pdo->table('plat_user')
    ->insert($data);
```

### insertAll()

[](#insertall)

```
$data = [
    ['name' => 'test1', 'permission' => 'xxx', 'ctime' => time(), 'gameids' => ''],
    ['name' => 'test2', 'permission' => 'xxx', 'ctime' => time(), 'gameids' => ''],
    ['name' => 'test3', 'permission' => 'xxx', 'ctime' => time(), 'gameids' => ''],
    ['name' => 'test4', 'permission' => 'xxx', 'ctime' => time(), 'gameids' => ''],
    ['name' => 'test5', 'permission' => 'xxx', 'ctime' => time(), 'gameids' => ''],
    ['name' => 'test6', 'permission' => 'xxx', 'ctime' => time(), 'gameids' => ''],
    ['name' => 'test7', 'permission' => 'xxx', 'ctime' => time(), 'gameids' => ''],
];

$rowCount = $pdo->table('plat_actor')->insertAll($data);
```

更新数据
----

[](#更新数据)

### update()

[](#update)

```
$data = ['actor' => 1];
//返回的是bool
$status = $pdo->table('plat_user')
    ->where(['id', '=', 1])
    ->update($data);
```

删除数据
----

[](#删除数据)

### delete()

[](#delete)

```
//删除
$status = $pdo->table('plat_user')
            ->where([['id', '=', '56']])
            ->delete();
```

事务
--

[](#事务)

### beginTransaction()

[](#begintransaction)

```
$pdo->beginTransaction();
```

### commit()

[](#commit)

```
$pdo->commit();
```

### rollBack()

[](#rollback)

```
$pdo->rollBack();
```

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~120 days

Total

5

Last Release

1266d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/7269a5ccf967c0f029f2c93c67081c47216a53bd4564f0cf5d6a2ca5f6778b48?d=identicon)[Kanin](/maintainers/Kanin)

---

Top Contributors

[![tangccy](https://avatars.githubusercontent.com/u/12172453?v=4)](https://github.com/tangccy "tangccy (12 commits)")

### Embed Badge

![Health badge](/badges/tjn-mpdo/health.svg)

```
[![Health](https://phpackages.com/badges/tjn-mpdo/health.svg)](https://phpackages.com/packages/tjn-mpdo)
```

###  Alternatives

[doctrine/orm

Object-Relational-Mapper for PHP

10.2k285.3M6.2k](/packages/doctrine-orm)[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k115.1M102](/packages/jdorn-sql-formatter)[illuminate/database

The Illuminate Database package.

2.8k52.4M9.4k](/packages/illuminate-database)[mongodb/mongodb

MongoDB driver library

1.6k64.0M546](/packages/mongodb-mongodb)[ramsey/uuid-doctrine

Use ramsey/uuid as a Doctrine field type.

90340.3M211](/packages/ramsey-uuid-doctrine)[reliese/laravel

Reliese Components for Laravel Framework code generation.

1.7k3.4M16](/packages/reliese-laravel)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
