PHPackages                             nstwf/mysql-connection - 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. nstwf/mysql-connection

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

nstwf/mysql-connection
======================

Reactphp MySQL transactional connection wrapper

1.2.2(10mo ago)5131[4 PRs](https://github.com/nstwfdev/mysql-connection/pulls)1MITPHPCI passing

Since Dec 20Pushed 3mo ago2 watchersCompare

[ Source](https://github.com/nstwfdev/mysql-connection)[ Packagist](https://packagist.org/packages/nstwf/mysql-connection)[ RSS](/packages/nstwf-mysql-connection/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (7)Dependencies (2)Versions (12)Used By (1)

Reactphp MySQL transactional connection
=======================================

[](#reactphp-mysql-transactional-connection)

[![CI](https://camo.githubusercontent.com/1c53cc9f69932e88bd2f1d9fe2a5df3a692eecb275ce64446265d92244773b1a/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6e737477666465762f6d7973716c2d636f6e6e656374696f6e2f63692e796d6c3f6272616e63683d6d6173746572266c6162656c3d6369266c6f676f3d676974687562)](https://github.com/nstwfdev/mysql-connection/actions?query=workflow%3Aci+branch%3Amaster)[![codecov](https://camo.githubusercontent.com/45eea8eb4706bb849cfc8b24b924fa3362409fe6c8baff188b504be99c45fe16/68747470733a2f2f636f6465636f762e696f2f67682f6e737477666465762f6d7973716c2d636f6e6e656374696f6e2f6272616e63682f6d61737465722f67726170682f62616467652e7376673f746f6b656e3d39594c3946534d345256)](https://codecov.io/gh/nstwfdev/mysql-connection)[![Packagist Version](https://camo.githubusercontent.com/1d5805f7ff1c15873f660c3302df94502d3091d239415d82f566835d13006594/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6e737477662f6d7973716c2d636f6e6e656374696f6e3f6c6f676f3d7061636b6167697374)](https://packagist.org/packages/nstwf/mysql-connection)

Simple wrapper of [`ConnectionInterface`](https://github.com/friends-of-reactphp/mysql) that allows you to make transactions easier

> Read [main documentation](https://github.com/friends-of-reactphp/mysql) before

**Table of contents**

- [Quickstart example](#quickstart-example)
- [Usage](#usage)
    - [Factory](#factory)
        - [createConnection()](#createConnection)
    - [ConnectionInterface](#connectioninterface)
        - [query()](#query)
        - [transaction()](#transaction)
        - [begin()](#begin)
        - [commit()](#commit)
        - [rollback()](#rollback)
        - [ping()](#ping)
        - [quit()](#quit)
        - [close()](#close)
- [Install](#install)
- [Tests](#tests)
- [License](#license)

Quickstart example
------------------

[](#quickstart-example)

```
$factory = new \Nstwf\MysqlConnection\Factory\ConnectionFactory(new \React\MySQL\Factory());
$connection = $factory->createConnection('localhost:3306');

$connection
    ->transaction(function (\Nstwf\MysqlConnection\ConnectionInterface $connection) {
        return $connection->query('update users set name = "Tim" where id = 3');
    })
    ->then(function () {
        echo 'OK';
    }, function (\Throwable $throwable) {
        echo $throwable->getMessage();
    });

$connection->quit();
```

Usage
-----

[](#usage)

### Factory

[](#factory)

The main role of factory - creating `ConnectionInterface`, by wrapping [`Factory`](https://github.com/friends-of-reactphp/mysql#factory)

#### createConnection

[](#createconnection)

Create connection using [lazy connection](https://github.com/friends-of-reactphp/mysql#createlazyconnection) for future operations.

```
$factory = new \Nstwf\MysqlConnection\Factory\ConnectionFactory(new \React\MySQL\Factory());
$connection = $factory->createConnection('localhost:3306');
```

### ConnectionInterface

[](#connectioninterface)

That's a wrapper of original `ConnectionInterface`.

> Currently main difference - wrapper does not support event emitter methods

[See original documentation](https://github.com/friends-of-reactphp/mysql#connectioninterface)

#### query

[](#query)

[See original documentation](https://github.com/friends-of-reactphp/mysql#query)

#### transaction

[](#transaction)

The `transaction(callable $callable): PromiseInterface` method can be used to perform a transaction.

```
$connection
    ->transaction(function (\Nstwf\MysqlConnection\ConnectionInterface $connection) {
        return $connection->query('update users set name = "Tim" where id = 3');
    })
    ->then(function () {
        echo 'OK';
    }, function (\Throwable $throwable) {
        echo $throwable->getMessage();
    });
```

Equals to:

```
$connection
    ->query("BEGIN")
    ->then(
        fn() => $connection->query("COMMIT"),
        function (\Throwable $throwable) use ($connection)  {
        return $connection->query("ROLLBACK")
                          ->then(fn() => $throwable);
        }
    );
```

#### begin

[](#begin)

The `begin(): PromiseInterface` method can be used to begin the transaction.

```
$connection
    ->begin()
    ->then(function () {
        echo 'Begin';
    }, function (\Throwable $throwable) {
        echo $throwable->getMessage();
    });
```

Equals to:

> Sql case-insensitive

```
$connection->query("BEGIN");
// or
$connection->query("START TRANSACTION");
```

#### commit

[](#commit)

The `commit(): PromiseInterface` method can be used to commit the transaction.

```
$connection
    ->commit()
    ->then(function () use ($connection) {
        echo 'Commit';
    }, function (\Throwable $throwable) {
        echo $throwable->getMessage();
    });
```

Equals to:

> sql case-insensitive

```
$connection->query("COMMIT");
```

#### rollback

[](#rollback)

The `rollback(): PromiseInterface` method can be used to rollback the transaction.

```
$connection
    ->rollback()
    ->then(function () use ($connection) {
        echo 'Rollback';
    }, function (\Throwable $throwable) {
        echo $throwable->getMessage();
    });
```

Equals to:

> Sql case-insensitive

```
$connection->query("ROLLBACK");
```

#### ping

[](#ping)

[See original documentation](https://github.com/friends-of-reactphp/mysql#ping)

#### close

[](#close)

[See original documentation](https://github.com/friends-of-reactphp/mysql#close)

#### quit

[](#quit)

[See original documentation](https://github.com/friends-of-reactphp/mysql#quit)

Install
-------

[](#install)

The recommended way to install this library is [through Composer](https://getcomposer.org). [New to Composer?](https://getcomposer.org/doc/00-intro.md)

This project follows [SemVer](https://semver.org/). This will install the latest supported version:

```
composer require nstwf/mysql-connection
```

See also the [CHANGELOG](docs/CHANGELOG.md) for details about version upgrades.

It's *highly recommended to use PHP 8+* \* for this project.

Tests
-----

[](#tests)

To run the test suite, you first need to clone this repo and then install all dependencies [through Composer](https://getcomposer.org):

```
composer install
```

To run the test suite, go to the project root and run:

```
vendor/bin/phpunit
```

License
-------

[](#license)

MIT, see [LICENSE file](LICENSE).

- [friends-of-reactphp/mysql](https://github.com/friends-of-reactphp/mysql) - main project

###  Health Score

41

—

FairBetter than 88% of packages

Maintenance74

Regular maintenance activity

Popularity16

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 77.8% 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 ~155 days

Recently: every ~233 days

Total

7

Last Release

301d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/6d1c9e30d7385c8913697b4c80e5cc75cfb2cba78abc541dc13cdc2a127ad412?d=identicon)[nstwf](/maintainers/nstwf)

---

Top Contributors

[![nstwfdev](https://avatars.githubusercontent.com/u/77036413?v=4)](https://github.com/nstwfdev "nstwfdev (35 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (10 commits)")

---

Tags

connectionmysqlreactphptransaction

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/nstwf-mysql-connection/health.svg)

```
[![Health](https://phpackages.com/badges/nstwf-mysql-connection/health.svg)](https://phpackages.com/packages/nstwf-mysql-connection)
```

###  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.3k](/packages/illuminate-database)[mongodb/mongodb

MongoDB driver library

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

Use ramsey/uuid as a Doctrine field type.

90340.3M209](/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)
