simple persistent connection test
[m6w6/ext-pq] / tests / trans001.phpt
1 --TEST--
2 transaction
3 --SKIPIF--
4 <?php include "_skipif.inc"; ?>
5 --FILE--
6 <?php
7 echo "Test\n";
8
9 include "_setup.inc";
10
11 $c = new pq\Connection(PQ_DSN);
12 $c->exec("DROP TABLE IF EXISTS test");
13 new pq\Event($c, pq\Event::NOTICE, function($c, $notice) {
14 echo "Got notice: $notice\n";
15 });
16 $t = new pq\Transaction($c);
17 $c->exec("DROP TABLE IF EXISTS test");
18 $c->exec("CREATE TABLE test (id serial, data text)");
19 $s = $c->prepare("test_insert", "INSERT INTO test (data) VALUES (\$1)", array((new pq\Types($c))["text"]->oid));
20 $s->exec(array("a"));
21 $s->exec(array("b"));
22 $s->exec(array("c"));
23 $r = $c->exec("SELECT * FROM test");
24 while ($row = $r->fetchRow(pq\Result::FETCH_OBJECT)) {
25 printf("%d => %s\n", $row->id, $row->data);
26 }
27 $t->rollback();
28 ?>
29 DONE
30 --EXPECT--
31 Test
32 Got notice: NOTICE: table "test" does not exist, skipping
33 Got notice: NOTICE: CREATE TABLE will create implicit sequence "test_id_seq" for serial column "test.id"
34 1 => a
35 2 => b
36 3 => c
37 DONE