Skip to content

Instantly share code, notes, and snippets.

@markkimsal
Created November 1, 2017 20:05
Show Gist options
  • Save markkimsal/2b8268142e2065f089fc62ffa8d7edad to your computer and use it in GitHub Desktop.
Save markkimsal/2b8268142e2065f089fc62ffa8d7edad to your computer and use it in GitHub Desktop.
Yield in Amphp\Mysql under Aerys Host
<?php
define('DB_HOST', 'db.service');
define('DB_USER', 'docker');
define('DB_PASS', 'mysql');
use \Amp\Loop;
use \Amp\Mysql\Pool;
use Aerys\{ Host, Request, Response, Websocket, function root, function router, function websocket };
return (new \Aerys\Host)->expose("*", 1337)->use(
function(Request $req, Response $res) {
$strConn = "host=".DB_HOST.";user=".DB_USER.";pass=".DB_PASS;
$sql = "SELECT * from mysql.user";
$pool = new Pool($strConn);
$resultSet = yield $pool->query($sql);
$rows = yield $resultSet->fetchAll();
$res->end("<html><body><h1>Fallback \o/</h1><p>".$sql."</p><p>Found: ". count($rows)." rows</p></body></html>");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment