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).
- 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
- Expose a non-blocking API for issuing multiple MySQL queries in parallel
- Support the full MySQL protocol and all available commands asynchronously
This package can be installed as a Composer dependency.
composer require amphp/mysql
- PHP 7.1+
- Amp framework (installed via composer)
More extensive code examples reside in the examples
directory.
Amp\Loop::run(function() {
$config = Amp\Mysql\ConnectionConfig::fromString(
"host=127.0.0.1 user=username password=password db=test"
);
/** @var \Amp\Mysql\Pool $pool */
$pool = Amp\Mysql\pool($config);
/** @var \Amp\Mysql\Statement $statement */
$statement = yield $pool->prepare("SELECT * FROM table_name WHERE id = :id");
/** @var \Amp\Mysql\ResultSet $result */
$result = yield $statement->execute(['id' => 1337]);
while (yield $result->advance()) {
$row = $result->getCurrent();
// $row is an associative array of column values. e.g.: $row['column_name']
}
});
amphp/mysql
follows the semver semantic versioning specification like all other amphp
packages.
If you discover any security related issues, please email contact@amphp.org
instead of using the issue tracker.
The MIT License (MIT). Please see LICENSE
for more information.