PHPackages                             kickpeach/database - 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. kickpeach/database

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

kickpeach/database
==================

a database component

0261PHP

Since Feb 6Pushed 7y ago1 watchersCompare

[ Source](https://github.com/KickPeach/database)[ Packagist](https://packagist.org/packages/kickpeach/database)[ RSS](/packages/kickpeach-database/feed)WikiDiscussions master Synced 4d ago

READMEChangelogDependenciesVersions (1)Used By (1)

database
========

[](#database)

基于PDO的kickpeach框架的databbase组件，亦可以独立使用，支持MySQl以及PostgreSQL数据库

怎么使用
====

[](#怎么使用)

- [安装](#%E5%AE%89%E8%A3%85)
- [使用](#%E4%BD%BF%E7%94%A8)
    - [get connection](#get-connection)
    - [insert and get insert id](#insert-and-get-insert-id)
    - [insert and get the number of rows affected](#insert-and-get-the-number-of-rows-affected)
    - [update and get the number of rows affected](#update-and-get-the-number-of-rows-affected)
    - [select](#select)
    - [delete and get the number of rows affected](#delete-and-get-the-number-of-rows-affected)
    - [transaction](#transaction)
    - [get query logs](#get-query-logs)
    - [execute the given callback in "dry run"(空转) mode](#execute-the-given-callback-in-dry-run%E7%A9%BA%E8%BD%AC-mode)
- [License](#license)

安装
--

[](#安装)

```
    composer require kickpeach/database -vvv
```

使用
--

[](#使用)

具体使用，可参考[tests](https://github.com/KickPeach/database/blob/master/tests/DatabaseTest.php)

### get connection

[](#get-connection)

- MySql

```
$dsn = sprintf('mysql:host=%s;port=%s;dbname=%s;charset=%s', '127.0.0.1', 3306, 'es_demo', 'utf8mb4');
$conn = new MySqlConnection($dsn, 'root', 123123);

```

- Postgres

```
$dsn = sprintf('pgsql:host=%s;port=%s;dbname=%s', '127.0.0.1', 3306, 'es_demo');
$conn = new PostgresConnection($dsn, 'root', 123123);

```

### insert and get insert id

[](#insert-and-get-insert-id)

```
$insertId = $conn->table('profile')->insertGetId([
    'name'      => 'test-name',
    'gender'    => 1,
    'birthday'  => '1988-12-01 01:00:01', //DATETIME
    'memo'      => 'this is a test memo',
    'lat'       => '30.54916000', //DECIMAL(10,8)
    'lng'       => '104.06761000' //DECIMAL(11,8)
]);

```

### insert and get the number of rows affected

[](#insert-and-get-the-number-of-rows-affected)

```
$affectNum = $conn->table('profile')->insert([
    [
        'name'      => 'test-name',
        'gender'    => 1,
        'birthday'  => '1988-12-01 01:00:01',
        'memo'      => 'this is a test memo',
        'lat'       => '30.54916000',
        'lng'       => '104.06761000'
    ],
    [
        'name'      => 'test-name-1',
        'gender'    => 1,
        'birthday'  => '2010-12-01 01:00:01',
        'memo'      => 'this is another test memo',
        'lat'       => '30.54916000',
        'lng'       => '104.06761000'
    ],
]);

```

### update and get the number of rows affected

[](#update-and-get-the-number-of-rows-affected)

```
affectNum = $conn->update('update profile set name = :name, memo = :memo where id = :id', [
    ':name'     => 'test-name',
    ':memo'     => 'this is another memo',
    ':id'       => $id,
]);

```

### select

[](#select)

```
$records = $conn->select('select * from profile where id = :id', [
    ':id'   => $id,
]);

```

### delete and get the number of rows affected

[](#delete-and-get-the-number-of-rows-affected)

```
$affectNum = $conn->delete('delete from profile where id = :id', [
    ':id'       => $id,
]);

```

### transaction

[](#transaction)

```
$conn->transaction(function ($conn) {
    //do something...
});

```

### get query logs

[](#get-query-logs)

```
$queryLogs = $conn->getQueryLog();

```

### execute the given callback in "dry run"(空转) mode

[](#execute-the-given-callback-in-dry-run空转-mode)

```
$conn->pretend(function ($conn) {
    //do something...
});

```

License
-------

[](#license)

[MIT](https://opensource.org/licenses/MIT)

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity38

Early-stage or recently created project

 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/4feffac62baecf873c8941e414747c4907f2110f1d31070d8a20fb1ecbf3e52a?d=identicon)[sevenshi](/maintainers/sevenshi)

---

Top Contributors

[![shisiying](https://avatars.githubusercontent.com/u/13288438?v=4)](https://github.com/shisiying "shisiying (3 commits)")

### Embed Badge

![Health badge](/badges/kickpeach-database/health.svg)

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

###  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)
