#25550 [NEW]: PostgreSQL query gives "undefined offset" error
| From: | chris at statgen dot ncsu dot edu | Date: | Mon, 15 Sep 2003 20:49:10 +0000 |
| Subject: | #25550 [NEW]: PostgreSQL query gives "undefined offset" error | ||
| Groups: | php.pear.dev | ||
| Request: | Send a blank email to pear-dev+get-21525@lists.php.net to get a copy of this message | ||
From: chris at statgen dot ncsu dot edu
Operating system: Win XP
PHP version: 4.3.1
PHP Bug Type: PEAR related
Bug description: PostgreSQL query gives "undefined offset" error
Description:
------------
On trying to fetch the next row from a PostgreSQL query using Pear DB you
get an "undefined offset" notice from within "fetchInto" in DB_pgsql in
pgsql.php.
I believe that this is caused by these two lines in DB_pgsql::freeResult:
unset($this->row[(int)$result]);
unset($this->num_rows[(int)$result]);
The problem is that the prepare used by getOne (eventually) returns the
same resource number that a real query query gets (the initial query in my
example code). So the row number and count for the initial query are
removed from the array.
Reproduce code:
---------------
$dbuser = "postgres";
$dbpass = 'xxxxxxxx';
require_once 'DB.php';
$dsn = "pgsql://$dbuser:$dbpass@localhost/dbname";
$db = DB::connect($dsn, FALSE);
if (!DB::isError($db)) $db->setFetchMode(DB_FETCHMODE_OBJECT);
// Now execute the same query but don't fetch the result row yet.
$res1 = $db->query("SELECT 'query 1' AS col1");
if (DB::isError($res1)) exit("First query failed");
// Now issue a bunch more queries using "getOne".
for ($i = 0; $i < 20; ++$i)
{
$parms = array($i);
$val = $db->getOne("SELECT ?", $parms);
}
// Try to get the row from the query issued before the "getOne" calls.
$row = $res1->fetchRow();
if (DB::isError($row)) exit("Fetch failed for query 1 row.");
print $row->col1;
Expected result:
----------------
Running with the CLI - expect to see "query 1" get printed on the console.
Actual result:
--------------
Notice: Undefined offset: 11 in c:\www\php\DB\pgsql.php on line 289
Notice: Undefined offset: 11 in c:\www\php\DB\pgsql.php on line 290
--
Edit bug report at http://bugs.php.net/?id=25550&edit=1
--
Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=25550&r=trysnapshot4
Try a CVS snapshot (php5): http://bugs.php.net/fix.php?id=25550&r=trysnapshot5
Fixed in CVS: http://bugs.php.net/fix.php?id=25550&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=25550&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=25550&r=needtrace
Try newer version: http://bugs.php.net/fix.php?id=25550&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=25550&r=support
Expected behavior: http://bugs.php.net/fix.php?id=25550&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=25550&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=25550&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=25550&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=25550&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=25550&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=25550&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=25550&r=gnused