PHPackages                             dustingraham/react-mysql - 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. dustingraham/react-mysql

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

dustingraham/react-mysql
========================

Non-blocking MySQLi database access with PHP. Designed to work with reactphp/react.

v0.1.1(10y ago)659MITPHPPHP &gt;=5.4.0

Since Apr 24Pushed 10y ago1 watchersCompare

[ Source](https://github.com/dustingraham/react-mysql)[ Packagist](https://packagist.org/packages/dustingraham/react-mysql)[ RSS](/packages/dustingraham-react-mysql/feed)WikiDiscussions master Synced 4w ago

READMEChangelog (5)Dependencies (3)Versions (6)Used By (0)

ReactMysql
==========

[](#reactmysql)

Non-blocking MySQLi database access with PHP. Designed to work with [reactphp/react](https://github.com/reactphp/react).

[![Build Status](https://camo.githubusercontent.com/bb873450532bdd8d652af6a247f08afacd126c4a1064d98dd3ef6df466f10512/68747470733a2f2f7472617669732d63692e6f72672f64757374696e67726168616d2f72656163742d6d7973716c2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/dustingraham/react-mysql)

Quickstart
----------

[](#quickstart)

```
$db = new \DustinGraham\ReactMysql\Database(
    ['localhost', 'apache', 'apache', 'react_mysql_test']
);

$db->statement('SELECT * FROM simple_table WHERE id = :test', [':test' => 2])
    ->then(function(\mysqli_result $result)
    {
        $rows = $result->fetch_all(MYSQLI_ASSOC);
    });

$db->shuttingDown = true;
$db->loop->run();

```

Setting `shuttingDown` to true will allow the loop to exit once the query has resolved.

Working
-------

[](#working)

This **is** working. But it is nowhere near complete. Check out the example file as well as the unit tests for more examples.

```
$ ./example
Creating database....done!
Run Query: 0
Found rows: 0
Run Query: 1
Found rows: 1
Current memory usage: 868.164K
Run Query: 2
Found rows: 1
Run Query: 3
Found rows: 1
Run Query: 4
Found rows: 0
Current memory usage: 868.164K
Run Query: 5
Found rows: 0
Current memory usage: 865.719K
Current memory usage: 865.719K
Current memory usage: 865.719K
Loop finished, all timers halted.

```

This won't work out of the box without the database configured. You will also need to set up a database with some data to query.

Unit Tests
----------

[](#unit-tests)

The example and unit tests expect a database called `react_mysql_test` which it will populate with the proper tables each time it runs. It also expects `localhost`and a user `apache` with password `apache`.

TODO
----

[](#todo)

This is not production ready. Still tons to do on the query builder. While I hate to reinvent the wheel, I have not found a lightweight injectable query builder that is not tied to a massive framework.

Plans (Future Examples)
-----------------------

[](#plans-future-examples)

These are just plans for now. It may change wildly as we develop.

### Current Development Example

[](#current-development-example)

Here is an example of what is currently working for the most part.

```
$db = new \DustinGraham\ReactMysql\Database(
    ['localhost', 'apache', 'apache', 'react_mysql_test']
);

$db->statement('SELECT * FROM simple_table WHERE id = :test', [':test' => 2])
    ->then(function(\mysqli_result $result)
    {
        $rows = $result->fetch_all(MYSQLI_ASSOC);

        // Do something with $rows.
    });

$db->shuttingDown = true;
$db->loop->run();

```

### Original Big Picture Plans

[](#original-big-picture-plans)

Here are some examples of how it may be, eventually. It would be nice to hide away some of the current boilerplate.

```
Connection::init($loop, ['db_host', 'db_user', 'db_pass', 'db_name']);

Connection::query(
  'SELECT * FROM `table` WHERE `column` = ? AND `column2` = ?;',
  ['red', 'white']
)->then(function($result) { ... });

Connection::query(...) returns a promise.

$db = new Database();
$db->createCommand('SELECT * FROM table WHERE id = :id', [':id' => 1])
  ->execute()
  ->then(function($results) {
      echo $results[0]->name;
  });

```

And another idea...

```
DB::loadModel('id', ' =', '3')->then(function($model) use ($socket) {
  $socket->send('Your name is '.$model->name);
});

```

Difficulties
------------

[](#difficulties)

There were many difficulties.

At this point, I can not find any libraries that handle parameterized queries without using PDO or prepared statements.

MYSQLI\_ASYNC does not support prepared statements and parameter binding. So we had to write it ourselves.

The mysqli::real\_escape\_string requires a link. But, the link is one of many. Last minute escaping once the command and connection were married from the pool. Could potentially have one dedicated link for escaping.

### Query Building Support

[](#query-building-support)

Many MySQL wrapper packages have been analyzed, but none are completely independent of a connection object that could be found.

For now, we will escape parameters, but require the user to provide a sql query that quotes the parameters.

This is obviously sub-optimal since a variable like $created\_at could be NOW() or '2016-01-01' or NULL.

The litmus test I have been using is the following query:

```
INSERT INTO `simple_table` (`id`, `name`, `value`, `created_at`)
VALUES (NULL, 'John\'s Name', 7, NOW());

```

The key points here are:

- Support for putting the parameter in quotes! This is the first step. The rest is intelligently knowing when not to quote.
- Support for a null value converted to NULL.
- Support for escaping the parameter using either \\' or '' is fine.
- Support for not escaping functions such as NOW()
- Support for recognizing integer values. Optional, since '7' will work fine.

### Wrapper Options Reviewed

[](#wrapper-options-reviewed)

1. [nilportugues/php-sql-query-builder](https://github.com/nilportugues/php-sql-query-builder) - No connection required! But, odd syntax.
2. [usmanhalalit/pixie](https://github.com/usmanhalalit/pixie) - Requires connection. Pretty close to needs.
3. [joshcam/PHP-MySQLi-Database-Class](https://github.com/joshcam/PHP-MySQLi-Database-Class) - Requires connection.
4. [aviat4ion/Query](https://git.timshomepage.net/aviat4ion/Query) - Requires connection.
5. [rkrx/php-mysql-query-builder](https://github.com/rkrx/php-mysql-query-builder) - Requires connection.
6. [stefangabos/Zebra\_Database](https://github.com/stefangabos/Zebra_Database) - Requires connection, does more than needed.
7. [indeyets/MySQL-Query-Builder](https://github.com/indeyets/MySQL-Query-Builder) - Not maintained. Odd syntax.

The nilportugues/php-sql-query-builder package is very close, but it does not quote the parameters.

Install
-------

[](#install)

The recommended way to install this library is through Composer.

```
$ composer require dustingraham/react-mysql

```

PHP 5.4 and the php ext-mysqli extension is required.

Credits
-------

[](#credits)

Much appreciation to the hard work over at [reactphp/react](https://github.com/reactphp/react).

Inspired by similar projects:

- [kaja47/async-mysql](https://github.com/kaja47/async-mysql)
- [bixuehujin/reactphp-mysql](https://github.com/bixuehujin/reactphp-mysql)

License
-------

[](#license)

DustinGraham/ReactMysql is released under the [MIT](https://github.com/dustingraham/react-mysql/blob/master/LICENSE) license.

###  Health Score

26

—

LowBetter than 41% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity52

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 ~6 days

Total

5

Last Release

3693d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1414400?v=4)[Dustin Graham](/maintainers/dustingraham)[@dustingraham](https://github.com/dustingraham)

---

Top Contributors

[![dustingraham](https://avatars.githubusercontent.com/u/1414400?v=4)](https://github.com/dustingraham "dustingraham (20 commits)")

---

Tags

asynchronousmysqlreact

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/dustingraham-react-mysql/health.svg)

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

###  Alternatives

[rector/rector-src

Instant Upgrade and Automated Refactoring of any PHP code

136406.3k14](/packages/rector-rector-src)[doctrine/dbal

Powerful PHP database abstraction layer (DBAL) with many features for database schema introspection and management.

9.7k605.0M6.5k](/packages/doctrine-dbal)[ccxt/ccxt

A cryptocurrency trading API with more than 100 exchanges in JavaScript / TypeScript / Python / C# / PHP / Go

43.2k341.0k1](/packages/ccxt-ccxt)[team-reflex/discord-php

An unofficial API to interact with the voice and text service Discord.

1.1k420.9k26](/packages/team-reflex-discord-php)[kirschbaum-development/eloquent-power-joins

The Laravel magic applied to joins.

1.6k32.6M42](/packages/kirschbaum-development-eloquent-power-joins)[scienta/doctrine-json-functions

A set of extensions to Doctrine that add support for json query functions.

58825.2M48](/packages/scienta-doctrine-json-functions)

PHPackages © 2026

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