Edit report at https://bugs.php.net/bug.php?id=60244&edit=1
ID: 60244 Comment by: bandy dot chris at gmail dot com Reported by: bandy dot chris at gmail dot com Summary: pg_fetch_* functions behave strangely with row = -1 Status: Open Type: Bug Package: PostgreSQL related Operating System: Gentoo Linux PHP Version: 5.3.8 Block user comment: N Private report: N New Comment: I've attached a patch against PHP_5_3_8. Previous Comments: ------------------------------------------------------------------------ [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