コード例 #1
0
ファイル: generic_table.php プロジェクト: amphp/mysql
function genTable(\Amp\Mysql\Pool $db)
{
    (yield $db->query("CREATE TABLE tmp SELECT 1 AS a, 2 AS b"));
    $promises = [];
    foreach (range(1, 5) as $num) {
        $promises[] = $db->query("INSERT INTO tmp (a, b) VALUES ({$num}, {$num} * 2)");
    }
    (yield \Amp\all($promises));
}
コード例 #2
0
ファイル: PoolTest.php プロジェクト: sagara-/mysql
 function testVirtualConnection()
 {
     $complete = false;
     (new NativeReactor())->run(function ($reactor) use(&$complete) {
         $db = new Pool("host=" . DB_HOST . ";user="******";pass="******";db=connectiontest", null, $reactor);
         /* Multiple queries one after the other must be hold back and dispatched to new connections */
         for ($i = 0; $i < 5; $i++) {
             $pings[] = $db->ping();
         }
         (yield \Amp\all($pings));
         $complete = true;
     });
     $this->assertEquals(true, $complete, "Database commands did not complete.");
 }