xref: /PHP-8.0/ext/pgsql/tests/09notice.phpt (revision 3171fec6)
1--TEST--
2PostgreSQL notice function
3--SKIPIF--
4<?php
5
6include("skipif.inc");
7
8_skip_lc_messages();
9
10?>
11--FILE--
12<?php
13include 'config.inc';
14include 'lcmess.inc';
15
16ini_set('pgsql.log_notice', TRUE);
17ini_set('pgsql.ignore_notice', FALSE);
18
19$db = pg_connect($conn_str);
20
21_set_lc_messages();
22
23$res = pg_query($db, 'SET client_min_messages TO NOTICE;');
24var_dump($res);
25
26// Get empty notice
27var_dump(pg_last_notice($db));
28var_dump(pg_last_notice($db, PGSQL_NOTICE_ALL));
29
30pg_query($db, "BEGIN;");
31pg_query($db, "BEGIN;");
32pg_query($db, "BEGIN;");
33pg_query($db, "BEGIN;");
34
35// Get notices
36var_dump(pg_last_notice($db));
37var_dump(pg_last_notice($db, PGSQL_NOTICE_ALL));
38
39// Clear and get notices
40var_dump(pg_last_notice($db, PGSQL_NOTICE_CLEAR));
41var_dump(pg_last_notice($db, PGSQL_NOTICE_LAST));
42var_dump(pg_last_notice($db, PGSQL_NOTICE_ALL));
43
44// Invalid option
45try {
46    var_dump(pg_last_notice($db, 99));
47} catch (\ValueError $e) {
48    echo $e->getMessage() . \PHP_EOL;
49}
50?>
51--EXPECTF--
52resource(%d) of type (pgsql result)
53string(0) ""
54array(0) {
55}
56
57Notice: pg_query(): %s already a transaction in progress in %s on line %d
58
59Notice: pg_query(): %s already a transaction in progress in %s on line %d
60
61Notice: pg_query(): %s already a transaction in progress in %s on line %d
62string(52) "WARNING:  there is already a transaction in progress"
63array(3) {
64  [0]=>
65  string(52) "WARNING:  there is already a transaction in progress"
66  [1]=>
67  string(52) "WARNING:  there is already a transaction in progress"
68  [2]=>
69  string(52) "WARNING:  there is already a transaction in progress"
70}
71bool(true)
72string(0) ""
73array(0) {
74}
75pg_last_notice(): Argument #2 ($mode) must be one of PGSQL_NOTICE_LAST, PGSQL_NOTICE_ALL, or PGSQL_NOTICE_CLEAR
76