xref: /PHP-8.1/ext/pgsql/tests/80_bug27597.phpt (revision 1f427779)
1--TEST--
2Bug #27597 (pg_fetch_array not returning false)
3--EXTENSIONS--
4pgsql
5--SKIPIF--
6<?php
7require_once('skipif.inc');
8?>
9--FILE--
10<?php
11
12require_once(__DIR__ . '/config.inc');
13
14$dbh = @pg_connect($conn_str);
15if (!$dbh) {
16    die ("Could not connect to the server");
17}
18
19@pg_query($dbh, "DROP TABLE id");
20pg_query($dbh, "CREATE TABLE id (id INT)");
21
22for ($i=0; $i<4; $i++) {
23    pg_query($dbh, "INSERT INTO id (id) VALUES ($i)");
24}
25
26function xi_fetch_array($res, $type = PGSQL_ASSOC) {
27    $a = pg_fetch_array($res, NULL, $type) ;
28    return $a ;
29}
30
31$res = pg_query($dbh, "SELECT * FROM id");
32$i = 0; // endless-loop protection
33while($row = xi_fetch_array($res)) {
34    print_r($row);
35    if ($i++ > 4) {
36        echo "ENDLESS-LOOP";
37        exit(1);
38    }
39}
40
41pg_close($dbh);
42
43?>
44--EXPECT--
45Array
46(
47    [id] => 0
48)
49Array
50(
51    [id] => 1
52)
53Array
54(
55    [id] => 2
56)
57Array
58(
59    [id] => 3
60)
61