forked from amphp/mysql
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path5-multi-stmts.php
29 lines (21 loc) · 931 Bytes
/
5-multi-stmts.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<?php
require 'support/bootstrap.php';
require 'support/generic-table.php';
use Amp\Mysql;
\Amp\Loop::run(function () {
$db = Mysql\pool(Mysql\ConnectionConfig::fromString("host=".DB_HOST.";user=".DB_USER.";pass=".DB_PASS.";db=".DB_NAME));
/* create same table than in 3-generic-with-yield.php */
yield from createGenericTable($db);
/* multi statements are enabled by default, but generally stored procedures also might return multiple resultsets anyway */
$result = yield $db->query("SELECT a + b FROM tmp; SELECT a - b FROM tmp;");
$i = 0;
/** @var Mysql\ResultSet $result */
do {
print PHP_EOL . "Query " . ++$i . " Results:" . PHP_EOL;
while (yield $result->advance()) {
\var_dump($result->getCurrent());
}
} while (yield $result->nextResultSet()); // Advances to the next result set.
yield $db->query("DROP TABLE tmp");
$db->close();
});