nstwf/mysql-connection 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

nstwf/mysql-connection

最新稳定版本:1.2.2

Composer 安装命令:

composer require nstwf/mysql-connection

包简介

Reactphp MySQL transactional connection wrapper

README 文档

README

CI codecov Packagist Version

Simple wrapper of ConnectionInterface that allows you to make transactions easier

Read main documentation before

Table of contents

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

Factory

The main role of factory - creating ConnectionInterface, by wrapping Factory

createConnection

Create connection using lazy connection for future operations.

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

ConnectionInterface

That's a wrapper of original ConnectionInterface.

Currently main difference - wrapper does not support event emitter methods

See original documentation

query

See original documentation

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

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

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

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

See original documentation

close

See original documentation

quit

See original documentation

Install

The recommended way to install this library is through Composer. New to Composer?

This project follows SemVer. This will install the latest supported version:

composer require nstwf/mysql-connection

See also the CHANGELOG for details about version upgrades.

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

Tests

To run the test suite, you first need to clone this repo and then install all dependencies through Composer:

composer install

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

vendor/bin/phpunit

License

MIT, see LICENSE file.

统计信息

  • 总下载量: 131
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 5
  • 点击次数: 0
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 5
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-12-20

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固