Bug #81274 [Fbk->Asn]: pg_fetch_all() last record is the same as previous one
| From: | yulkusal at gmail dot com | Date: | Tue, 20 Jul 2021 10:46:06 +0000 |
| Subject: | Bug #81274 [Fbk->Asn]: pg_fetch_all() last record is the same as previous one | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-235201@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=81274&edit=1
ID: 81274
User updated by: yulkusal at gmail dot com
Reported by: yulkusal at gmail dot com
Summary: pg_fetch_all() last record is the same as previous
one
-Status: Feedback
+Status: Assigned
Type: Bug
Package: PostgreSQL related
Operating System: Centos 8.4
PHP Version: 7.4.21
Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
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.
Previous Comments:
------------------------------------------------------------------------
[2021-07-20 09:08:09] 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-19 18:06:04] 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;
}
}
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=81274&edit=1