Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 1.3.0

Bug #1915 Undefined Offset when doing fetchRow
Submitted: 2004-07-20 04:55 UTC
From: brain at jbrain dot com Assigned: quipo
Status: Bogus Package: MDB
PHP Version: 4.3.7 OS: Windows
Roadmaps: (Not assigned)    
Subscription  


 [2004-07-20 04:55 UTC] brain at jbrain dot com
Description: ------------ I am using PHP 4.3.8 on WinXP and Apache When using PEAR_MDB 1.30 MySQL DB, I can read in 1 row of data as per the tutorial. However, when I go to read in the second line of data, I get "Undefined Offset" in fetchInto method, called from fetchRow... I tracked the issue down to: Common.php, line 3737: if (!$this->options['autofree'] || $row != NULL) { $this->freeResult($result); } I have autofree off, and the row is not null, so the result is freed. Unless I am mistaken, it would seem this code should be: // if autofree on and returned row = NULL, free RS. if ($this->options['autofree'] && $row == NULL) { $this->freeResult($result); } Reproduce code: --------------- Any query that returns more than 1 row of data shows the issue: $mdb=&MDB::connect((array("phptype"=>"mysql","username"=>"ODBC","password"=>"password"))); $mdb->setDatabase("eweb"); $query="..."; $result=$mdb->query($query); if(MDB::isError($result)) { die($result->getMessage()); } while($data=$mdb->fetchRow($result)) { echo $data; //replace with actual code. } Expected result: ---------------- Rows of data Actual result: -------------- Only one row

Comments

 [2004-07-20 07:25 UTC] quipo
fetchRow() frees the results just after fetching the first row of the result, just like fetchCol() and fetchOne(). You need to use fetchInto(): while ($data = $mdb->fetchInto($result)) { var_dump($data); //replace with actual code. } HTH Regards, -- Lorenzo Alberton http://pear.php.net/user/quipo