php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #81274 pg_fetch_all() last record is the same as previous one
Submitted: 2021-07-19 18:06 UTC Modified: 2021-07-20 10:50 UTC
From: yulkusal at gmail dot com Assigned: cmb (profile)
Status: Not a bug Package: PostgreSQL related
PHP Version: 7.4.21 OS: Centos 8.4
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: yulkusal at gmail dot com
New email:
PHP Version: OS:

 

 [2021-07-19 18:06 UTC] yulkusal at gmail dot com
Description:
------------
The last element of pg_fetch_all() array result is the same as the previous one (n and n-1 are the same).
Using pg_fetch_assoc() shows correct information.


PHP Info:
System 	Linux qm 4.18.0-305.7.1.el8_4.x86_64 #1 SMP Tue Jun 29 21:55:12 UTC 2021 x86_64 
Build Provider 	Remi's RPM repository <https://rpms.remirepo.net/> 
Server API 	FPM/FastCGI 
PHP API 	20190902 

PostgreSQL(libpq) Version 	13.2 
PostgreSQL(libpq) PostgreSQL 13.2 on x86_64-redhat-linux-gnu, compiled by gcc (GCC) 8.4.1 20200928 (Red Hat 8.4.1-1), 64-bit 

Postgresql Info: PostgreSQL 12.7 from postgresql repo
postgresql12.x86_64  /  12.7-2PGDG.rhel8 / @pgdg12



Test script:
---------------
$res = pg_query($db_connection, 'SELECT field01 FROM table01');
$num = pg_num_rows($res);
if($num > 0){
	$arr = pg_fetch_all($res);
	foreach($arr as $rec){
		echo $rec['field1'] . PHP_EOL;
	}
	for($i = 0; $i < $num; $i++){
		$rec = pg_fetch_assoc($res);
		echo $rec['field1'] . PHP_EOL;
	}
}


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-07-20 09:08 UTC] cmb@php.net
-Status: Open +Status: Feedback -Assigned To: +Assigned To: cmb
 [2021-07-20 09:08 UTC] cmb@php.net
I cannot reproduce this with PHP-7.4 on Windows using PostGreSQL
10.

Can you please provide a *self-contained* reproduce script.
 [2021-07-20 10:46 UTC] yulkusal at gmail dot com
-Status: Feedback +Status: Assigned
 [2021-07-20 10:46 UTC] yulkusal at gmail dot com
Sorry, it is embarrassing.
It is a not a bug.

The problem was a “foreach” statement where the value was assigned by reference (manual page warns about this).
I became aware when I was creating the *self-contained* reproduce script.

Sorry for the trouble.
 [2021-07-20 10:50 UTC] cmb@php.net
-Status: Assigned +Status: Not a bug
 [2021-07-20 10:50 UTC] cmb@php.net
No worries. :)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu May 02 13:01:30 2024 UTC