PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » Database » DB » Bug #3016

Bug in DB_pgsql::fetchInto when using a row number

Details

Submitted2004-12-22 17:15 UTC
Fromteixeira at mcs dot suffolk dot edu
Assigneddanielc
StatusBogus
PackageDB
PHP Version5.0.2
OSLinux/2.6.3
Roadmaps(Not assigned)

Comments

[2004-12-22 17:15 UTC] teixeira at mcs dot suffolk dot edu

Description:
------------
I am using PEAR DB v.1.6.8. The code I was trying to execute was as follows:

$data = $result->fetchRow(DB_FETCHMODE_ASSOC, $i);

where $i is an index that will not always be a sequential number of rows. When executing this code, the page would only half load and when looking at my Apache logs, I would get log entries like:

[notice] child pid 4280 exit signal Segmentation fault (11)

The way I was able to fix it in my version of pgsql.php was to patch the pgsql.php file with the following:

--- DB-1.6.8/DB/pgsql.php 2004-10-04 13:53:09.000000000 -0400
+++ /usr/lib/php/DB/pgsql.php 2004-12-22 12:07:13.850735276 -0500
@@ -290,6 +290,7 @@
*/
function fetchInto($result, &$arr, $fetchmode, $rownum=null)
{
+ ($rownum == null) ? $doInc = true : $doInc = false;
$result_int = (int)$result;
$rownum = ($rownum !== null) ? $rownum : $this->row[$result_int];
if ($rownum >= $this->num_rows[$result_int]) {
@@ -316,7 +317,9 @@
if ($this->options['portability'] & DB_PORTABILITY_NULL_TO_EMPTY) {
$this->_convertNullArrayValuesToEmpty($arr);
}
- $this->row[$result_int] = ++$rownum;
+ if ($doInc) {
+ $this->row[$result_int] = ++$rownum;
+ }
return DB_OK;
}

After using this patch, everything seems to work as it should.

Reproduce code:
---------------
The basic code to reproduce this can be found at the following URL:

http://cartan.cas.suffolk.edu/test/db-broken.phps

Expected result:
----------------
The code above should output staggered rows from the query (this is intended to be used in this manner to create columns of data on a webpage). The out to this code should be several lines of data of the form:

Array ( [field1] => 1 [field2] => 2 [field3] => 3 )

where field names and values will vary depending upon the table's field names and values. Basically, the output will be the values of the arrays (using print_r) printed in an order consistant with the index values

Actual result:
--------------
The output will sometimes be the same, sometimes different, but the web server (Apache) will always give the

[notice] child pid 4280 exit signal Segmentation fault (11)

error message in the error log.

In my actual script, the error causes the seg fault causes the page to only half-display since the seg fault causes the page transmission to die randomly. Also, the postgre logs report

unexpected EOF on client connection

but this is most likely caused by the seg fault since it cuts the connection to the database prematurely.