From:
Operating system: Gentoo Linux
PHP version: 5.3.8
Package: PostgreSQL related
Bug Type: Bug
Bug description:pg_fetch_* functions behave strangely with row = -1
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 bug report at https://bugs.php.net/bug.php?id=60244&edit=1
--
Try a snapshot (PHP 5.4):
https://bugs.php.net/fix.php?id=60244&r=trysnapshot54
Try a snapshot (PHP 5.3):
https://bugs.php.net/fix.php?id=60244&r=trysnapshot53
Try a snapshot (trunk):
https://bugs.php.net/fix.php?id=60244&r=trysnapshottrunk
Fixed in SVN:
https://bugs.php.net/fix.php?id=60244&r=fixed
Fixed in SVN and need be documented:
https://bugs.php.net/fix.php?id=60244&r=needdocs
Fixed in release:
https://bugs.php.net/fix.php?id=60244&r=alreadyfixed
Need backtrace:
https://bugs.php.net/fix.php?id=60244&r=needtrace
Need Reproduce Script:
https://bugs.php.net/fix.php?id=60244&r=needscript
Try newer version:
https://bugs.php.net/fix.php?id=60244&r=oldversion
Not developer issue:
https://bugs.php.net/fix.php?id=60244&r=support
Expected behavior:
https://bugs.php.net/fix.php?id=60244&r=notwrong
Not enough info:
https://bugs.php.net/fix.php?id=60244&r=notenoughinfo
Submitted twice:
https://bugs.php.net/fix.php?id=60244&r=submittedtwice
register_globals:
https://bugs.php.net/fix.php?id=60244&r=globals
PHP 4 support discontinued:
https://bugs.php.net/fix.php?id=60244&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=60244&r=dst
IIS Stability:
https://bugs.php.net/fix.php?id=60244&r=isapi
Install GNU Sed:
https://bugs.php.net/fix.php?id=60244&r=gnused
Floating point limitations:
https://bugs.php.net/fix.php?id=60244&r=float
No Zend Extensions:
https://bugs.php.net/fix.php?id=60244&r=nozend
MySQL Configuration Error:
https://bugs.php.net/fix.php?id=60244&r=mysqlcfg