-
-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy path2-transaction.php
34 lines (22 loc) · 958 Bytes
/
2-transaction.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
30
31
32
33
34
#!/usr/bin/env php
<?php declare(strict_types=1);
require dirname(__DIR__) . '/vendor/autoload.php';
use Amp\Postgres\PostgresConfig;
use Amp\Postgres\PostgresConnectionPool;
$config = PostgresConfig::fromString('host=localhost user=postgres');
$pool = new PostgresConnectionPool($config);
$pool->query('DROP TABLE IF EXISTS test');
$transaction = $pool->beginTransaction();
$transaction->query('CREATE TABLE test (domain VARCHAR(63), tld VARCHAR(63), PRIMARY KEY (domain, tld))');
$statement = $transaction->prepare('INSERT INTO test VALUES (?, ?)');
$statement->execute(['amphp', 'org']);
$statement->execute(['google', 'com']);
$statement->execute(['github', 'com']);
$result = $transaction->execute('SELECT * FROM test WHERE tld = :tld', ['tld' => 'com']);
$format = "%-20s | %-10s\n";
printf($format, 'TLD', 'Domain');
foreach ($result as $row) {
printf($format, $row['domain'], $row['tld']);
}
$transaction->rollback();
$pool->close();