php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #23712 DB_DataObject: fetch() fails after delete() within loop
Submitted: 2003-05-20 05:29 UTC Modified: 2003-05-21 20:02 UTC
From: mccarthy at ee dot ualberta dot ca Assigned: alan_k (profile)
Status: Closed Package: PEAR related
PHP Version: 4.3.1 OS: Linux RedHat
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: mccarthy at ee dot ualberta dot ca
New email:
PHP Version: OS:

 

 [2003-05-20 05:29 UTC] mccarthy at ee dot ualberta dot ca
The following pieces of code fail in all of my projects:

$ca = new DataObjects_Categories;
$ca->get(<some id>);
$ca->deleteAll();

Where the class DataObjects_Categories is defined as:

class DataObjects_Categories extends DB_DataObject {

<... snip ...>

    function &getSubCategories() {
      $scs = new DataObjects_Sub_categories;
      $scs->ca_id = $this->id;
      $scs->find();
      return $scs;
    }

    function deleteAll() {
      DB_DataObject::debugLevel(1);

      $sc = $this->getSubCategories();
      while ($sc->fetch()) {
        $sc->delete();
      }
      $this->delete();

      DB_DataObject::debugLevel();
    }

<... snip ...>

}

The script, with debugLevel(1), returns:

*--*

__find 
sql QUERYSELECT * FROM sub_categories  WHERE  sub_categories.ca_id = 33   
query DONE QUERY
__find CHECK autofetchd 
__find DONE
fetchrow sub_categories DONE
sql QUERYDELETE FROM sub_categories  WHERE  sub_categories.id = 132
query DONE QUERY

Fatal error: Call to a member function on a non-object in pear/lib/php/DB/DataObject.php on line 385

*--*

There were three sub_categories in the database that should have been deleted during this execution.  However, the fetch() loop only gets executed once before the fatal error.  Two sub_categories and their parent category remain.

I believe the bug lies in the fetch() statement of:

  while ($sc->fetch()) {
    $sc->delete();
  }

where it appears to fail after the first loop.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-05-20 07:58 UTC] alan_k@php.net
can you try the cvs version, I've just commited a fix that 'should' fix this.

http://cvs.php.net/co.php/pear/DB_DataObject/DataObject.php?r=1.9

Regards
Alan
 [2003-05-21 06:14 UTC] mccarthy at ee dot ualberta dot ca
Nothing has changed:

Fatal error: Call to a member function on a non-object in DB/DataObject.php on line 385

Again, one child is deleted and two remain.

Let me know if there is anything I can do to help.

Kind Regards,
Mike
 [2003-05-21 06:22 UTC] mccarthy at ee dot ualberta dot ca
Never mind the last post!!!  I am silly.  Here are the results of the real (successful) test:

__find 
sql QUERYSELECT * FROM sub_categories  WHERE  sub_categories.sc_id = 33   
query DONE QUERY
__find CHECK autofetchd 
__find DONE
fetchrow sub_categories DONE
sql QUERYDELETE FROM sub_categories  WHERE  sub_categories.id = 137
query DONE QUERY
fetchrow sub_categories DONE
sql QUERYDELETE FROM sub_categories  WHERE  sub_categories.id = 136
query DONE QUERY
fetchrow sub_categories DONE
sql QUERYDELETE FROM sub_categories  WHERE  sub_categories.id = 134
query DONE QUERY
sql QUERYDELETE FROM categories  WHERE  categories.id = 33
query DONE QUERY

Many thanks Alan!
 [2003-05-21 20:02 UTC] alan_k@php.net
ok ready to press a release.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 03 09:01:34 2025 UTC