xref: /PHP-8.3/ext/pgsql/tests/bug60244.phpt (revision 1f427779)
1--TEST--
2Bug #60244 (pg_fetch_* functions do not validate that row param is >0)
3--EXTENSIONS--
4pgsql
5--SKIPIF--
6<?php
7include("skipif.inc");
8?>
9--FILE--
10<?php
11
12include 'config.inc';
13
14$db = pg_connect($conn_str);
15$result = pg_query($db, "select 'a' union select 'b'");
16
17try {
18    var_dump(pg_fetch_array($result, -1));
19} catch (\ValueError $e) {
20    echo $e->getMessage() . \PHP_EOL;
21}
22try {
23    var_dump(pg_fetch_assoc($result, -1));
24} catch (\ValueError $e) {
25    echo $e->getMessage() . \PHP_EOL;
26}
27try {
28    var_dump(pg_fetch_object($result, -1));
29} catch (\ValueError $e) {
30    echo $e->getMessage() . \PHP_EOL;
31}
32try {
33    var_dump(pg_fetch_row($result, -1));
34} catch (\ValueError $e) {
35    echo $e->getMessage() . \PHP_EOL;
36}
37
38var_dump(pg_fetch_array($result, 0));
39var_dump(pg_fetch_assoc($result, 0));
40var_dump(pg_fetch_object($result, 0));
41var_dump(pg_fetch_row($result, 0));
42
43pg_close($db);
44
45?>
46--EXPECTF--
47pg_fetch_array(): Argument #2 ($row) must be greater than or equal to 0
48pg_fetch_assoc(): Argument #2 ($row) must be greater than or equal to 0
49pg_fetch_object(): Argument #2 ($row) must be greater than or equal to 0
50pg_fetch_row(): Argument #2 ($row) must be greater than or equal to 0
51array(2) {
52  [0]=>
53  string(1) "a"
54  ["?column?"]=>
55  string(1) "a"
56}
57array(1) {
58  ["?column?"]=>
59  string(1) "a"
60}
61object(stdClass)#%d (1) {
62  ["?column?"]=>
63  string(1) "a"
64}
65array(1) {
66  [0]=>
67  string(1) "a"
68}
69