Created
November 1, 2017 20:05
-
-
Save markkimsal/2b8268142e2065f089fc62ffa8d7edad to your computer and use it in GitHub Desktop.
Yield in Amphp\Mysql under Aerys Host
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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