Bug #60244 [Opn->Csd]: pg_fetch_* functions behave strangely with row = -1
Edit report at https://bugs.php.net/bug.php?id=60244&edit=1
ID: 60244
Updated by: iliaa@php.net
Reported by: bandy dot chris at gmail dot com
Summary: pg_fetch_* functions behave strangely with row = -1
-Status: Open
+Status: Closed
Type: Bug
Package: PostgreSQL related
Operating System: Gentoo Linux
PHP Version: 5.3.8
-Assigned To:
+Assigned To: iliaa
Block user comment: N
Private report: N
New Comment:
This bug has been fixed in SVN.
Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
For Windows:
http://windows.php.net/snapshots/
Thank you for the report, and for helping us make PHP better.
Previous Comments:
------------------------------------------------------------------------
[2011-11-15 18:02:48] iliaa@php.net
Automatic comment from SVN on behalf of iliaa
Revision: http://svn.php.net/viewvc/?view=revision&revision=319259
Log: Fixed bug #60244 (pg_fetch_* functions do not validate that row param is >0).
------------------------------------------------------------------------
[2011-11-09 03:41:30] bandy dot chris at gmail dot com
I've attached a patch against PHP_5_3_8.
------------------------------------------------------------------------
[2011-11-08 16:55:07] bandy dot chris at gmail dot com
Description:
------------
pg_fetch_array(), pg_fetch_assoc(), pg_fetch_object() and pg_fetch_row() neglect to raise a warning
when requesting $row = -1. In some cases, -1 is interpreted as though $row = NULL.
pg_fetch_result() is not affected.
Test script:
---------------
<?php
error_reporting(E_ALL);
$conn = pg_connect('host=localhost dbname=postgres');
$result = pg_query("select 'a' union select 'b'");
var_dump(pg_fetch_row($result, -1));
var_dump(pg_fetch_row($result, -1));
$result = pg_query("select 'a' union select 'b'");
var_dump(pg_fetch_row($result, -2));
var_dump(pg_fetch_row($result, -1));
var_dump(pg_fetch_row($result, -1));
$result = pg_query("select 'a' union select 'b'");
var_dump(pg_fetch_row($result, 0));
var_dump(pg_fetch_row($result, -1));
var_dump(pg_fetch_row($result, -1));
Expected result:
----------------
PHP Warning: pg_fetch_row(): Unable to jump to row -1 on PostgreSQL result index 5 in pgsql_bug.php
on line 6
Warning: pg_fetch_row(): Unable to jump to row -1 on PostgreSQL result index 5 in pgsql_bug.php on
line 6
bool(false)
PHP Warning: pg_fetch_row(): Unable to jump to row -1 on PostgreSQL result index 5 in pgsql_bug.php
on line 7
Warning: pg_fetch_row(): Unable to jump to row -1 on PostgreSQL result index 5 in pgsql_bug.php on
line 7
bool(false)
PHP Warning: pg_fetch_row(): Unable to jump to row -2 on PostgreSQL result index 6 in pgsql_bug.php
on line 10
Warning: pg_fetch_row(): Unable to jump to row -2 on PostgreSQL result index 6 in pgsql_bug.php on
line 10
bool(false)
PHP Warning: pg_fetch_row(): Unable to jump to row -1 on PostgreSQL result index 6 in pgsql_bug.php
on line 11
Warning: pg_fetch_row(): Unable to jump to row -1 on PostgreSQL result index 6 in pgsql_bug.php on
line 11
bool(false)
PHP Warning: pg_fetch_row(): Unable to jump to row -1 on PostgreSQL result index 6 in pgsql_bug.php
on line 12
Warning: pg_fetch_row(): Unable to jump to row -1 on PostgreSQL result index 6 in pgsql_bug.php on
line 12
bool(false)
array(1) {
[0]=>
string(1) "a"
}
PHP Warning: pg_fetch_row(): Unable to jump to row -1 on PostgreSQL result index 7 in pgsql_bug.php
on line 16
Warning: pg_fetch_row(): Unable to jump to row -1 on PostgreSQL result index 7 in pgsql_bug.php on
line 16
bool(false)
PHP Warning: pg_fetch_row(): Unable to jump to row -1 on PostgreSQL result index 7 in pgsql_bug.php
on line 17
Warning: pg_fetch_row(): Unable to jump to row -1 on PostgreSQL result index 7 in pgsql_bug.php on
line 17
bool(false)
Actual result:
--------------
array(1) {
[0]=>
string(1) "a"
}
array(1) {
[0]=>
string(1) "b"
}
PHP Warning: pg_fetch_row(): Unable to jump to row -2 on PostgreSQL result index 6 in pgsql_bug.php
on line 10
Warning: pg_fetch_row(): Unable to jump to row -2 on PostgreSQL result index 6 in pgsql_bug.php on
line 10
bool(false)
bool(false)
bool(false)
array(1) {
[0]=>
string(1) "a"
}
array(1) {
[0]=>
string(1) "a"
}
array(1) {
[0]=>
string(1) "b"
}
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=60244&edit=1
Thread (3 messages)