php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #76548 pg_fetch_result did not fetch the next row
Submitted: 2018-06-29 14:41 UTC Modified: -
From: sukei13 at gmail dot com Assigned:
Status: Closed Package: PostgreSQL related
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: sukei13 at gmail dot com
New email:
PHP Version: OS:

 

 [2018-06-29 14:41 UTC] sukei13 at gmail dot com
Description:
------------
pg_fetch_result used in its short form: pg_fetch_result(resource $result, mixed $field). should fetch the next row each time it's called according to the documentation and the behavior of the other pg_fetch_* behavior.

in php-src, the pg_result->row internal counter is never incremented. This result in fetching the same row endlessly.

https://github.com/php/php-src/blob/php5_5_0/ext/pgsql/pgsql.c#L1182:L1188

Test script:
---------------
<?php

$connection = pg_connect('...');

$result = pg_query($connection, 'SELECT v FROM (VALUES (1), (2), (3)) AS t(v)'):

// cause an infinite loop since the pg_fetch_result func fetch the first value endlessly.
while ($value = pg_fetch_result($result, 0)) {
  var_dump($value); // should be 1, 2 then 3.
}

Expected result:
----------------
1, 2, 3

Actual result:
--------------
1, 1, 1, 1, 1, ...

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-06-29 16:36 UTC] ab@php.net
Automatic comment on behalf of ab
Revision: http://git.php.net/?p=php-src.git;a=commit;h=cb97fd309790330bced04091fac46ea1466283c9
Log: Fixed bug #76548 pg_fetch_result did not fetch the next row
 [2018-06-29 16:36 UTC] ab@php.net
-Status: Open +Status: Closed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 12:01:29 2024 UTC