Asynchronous & non-blocking MySQL driver for React.PHP
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
src/Atrox
.gitignore
LICENSE
README.md
composer.json

README.md

AsyncMysql

Asynchronous & non-blocking MySQL driver for React.PHP.

Install

Add this crap to your composer.json:

{
  "require": {
    "atrox/async-mysql": "dev-master"
  },
  "repositories": [
    {
      "type": "vcs",
      "url": "https://github.com/kaja47/async-mysql"
    }
  ]
}

Usage

Create instance of AsyncMysql and call method query. It returns Promise of mysqli_result that will be resolved imediately after query completes.

<?php

$loop = React\EventLoop\Factory::create();

$makeConnection = function () {
  return mysqli_connect('localhost', 'user', 'pass', 'dbname');
};

$mysql = new Atrox\AsyncMysql($loop, $makeConnection);
$mysql->query('select * from ponies_and_unicorns')->then(
  function ($result) { writeHttpResponse(json_encode($result->fetch_all(MYSQLI_ASSOC))); $result->close(); },
  function ($error)  { writeHeader500(); }
);