xref: /PHP-8.2/ext/pgsql/tests/80_bug36625.phpt (revision 7a411564)
1--TEST--
2Bug #36625 (8.0+) (pg_trace() does not work)
3--EXTENSIONS--
4pgsql
5--SKIPIF--
6<?php
7require_once('skipif.inc');
8?>
9--FILE--
10<?php
11
12require_once('config.inc');
13
14$dbh = @pg_connect($conn_str);
15if (!$dbh) {
16    die ('Could not connect to the server');
17}
18
19$tracefile = __DIR__ . '/trace.tmp';
20
21@unlink($tracefile);
22var_dump(file_exists($tracefile));
23
24pg_trace($tracefile, 'w', $dbh);
25$res = pg_query($dbh, 'select 1');
26var_dump($res);
27pg_close($dbh);
28
29$found = 0;
30function search_trace_file($line)
31{
32    if (strpos($line, '"select 1"') !== false || strpos($line, "'select 1'") !== false) {
33        $GLOBALS['found']++;
34    }
35}
36
37$trace = file($tracefile);
38array_walk($trace, 'search_trace_file');
39var_dump($found > 0);
40var_dump(file_exists($tracefile));
41
42?>
43--CLEAN--
44<?php
45$tracefile = __DIR__ . '/trace.tmp';
46unlink($tracefile);
47?>
48--EXPECTF--
49bool(false)
50object(PgSql\Result)#%d (0) {
51}
52bool(true)
53bool(true)
54