Async MySQL client built with Amp.
amp/mysql
is an asynchronous MySQL client built on the Amp concurrency framework. The library exposes a Promise-based API to dynamically query multiple MySQL connections concurrently. The client transparently distributes these queries across a scalable pool of available connections and does so using 100% userland PHP; there are no external extension dependencies (e.g. ext/mysqli
, ext/pdo
, etc).
Features
- Asynchronous API exposing full single-threaded concurrency
- Transparent connection pooling to overcome MySQL's fundamentally synchronous connection protocol
- MySQL transfer encoding support (gzip, TLS encryption)
- Support for all MySQL commands†
† As documented in official Mysql Internals Manual
Project Goals
- Expose a non-blocking API for issuing multiple MySQL queries in parallel
- Support the full MySQL protocol and all available commands asynchronously
Installation
This package can be installed as a Composer dependency.
composer require amphp/mysql
Requirements
- PHP 7.0+
- Amp framework (installed via composer)
Documentation & Examples
More extensive code examples reside in the examples
directory.
\Amp\Loop::run(function() {
/** @var \Amp\Mysql\Pool $pool */
$pool = Amp\Mysql\pool("host=127.0.0.1 user=username password=password db=test");
/** @var \Amp\Mysql\Statement $statement */
$statement = yield $pool->prepare("SELECT * FROM table_name WHERE id=?");
/** @var \Amp\Mysql\ResultSet $result */
$result = yield $statement->execute([1337]);
while (yield $result->advance()) {
$row = $result->getCurrent();
// $row is an associative array of column values. e.g.: $row['column_name']
}
});
Versioning
amphp/mysql
follows the semver semantic versioning specification like all other amphp
packages.
Security
If you discover any security related issues, please email contact@amphp.org
instead of using the issue tracker.
License
The MIT License (MIT). Please see LICENSE
for more information.