-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtransaction.php
More file actions
58 lines (43 loc) · 1.61 KB
/
Copy pathtransaction.php
File metadata and controls
58 lines (43 loc) · 1.61 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
/**
* This file is part of the Makise-Co Postgres Client
* World line: 0.571024a
*
* (c) Dmitry K. <coder1994@gmail.com>
*/
declare(strict_types=1);
require \dirname(__DIR__) . '/../vendor/autoload.php';
use MakiseCo\Postgres\ConnectionConfigBuilder;
use MakiseCo\Postgres\PostgresPool;
use function Swoole\Coroutine\run;
run(
static function () {
$connectionConfig = (new ConnectionConfigBuilder())
->withHost('127.0.0.1')
->withPort(5432)
->withUser('makise')
->withPassword('el-psy-congroo')
->withDatabase('makise')
->build();
$pool = new PostgresPool($connectionConfig);
$pool->setMaxActive(1);
$pool->setMinActive(0);
$pool->init();
$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']);
/** @var \MakiseCo\SqlCommon\Contracts\ResultSet $result */
$result = $transaction->execute('SELECT * FROM test WHERE tld = :tld', ['tld' => 'com']);
$format = "%-20s | %-10s\n";
printf($format, 'TLD', 'Domain');
while ($row = $result->fetchAssoc()) {
printf($format, $row['domain'], $row['tld']);
}
$transaction->rollback();
$pool->close();
}
);