php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #5416 MySQL result ids are cleared even while inside a class
Submitted: 2000-07-06 21:29 UTC Modified: 2000-07-24 09:09 UTC
From: sean at fifthace dot com Assigned:
Status: Closed Package: MySQL related
PHP Version: 4.0.1pl2 OS: FreeBSD 3.3-RELEASE
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: sean at fifthace dot com
New email:
PHP Version: OS:

 

 [2000-07-06 21:29 UTC] sean at fifthace dot com
If I try to run a query in a class constructor and then save the MySQL result id for use later in the class, I can't.  It seems that as soon as PHP exits the constructor the MySQL result id is cleaned up and is no longer valid for calls to the class methods.

Example (note: not real code :-):

mysql_pconnect( blab, blah, blah );
mysql_select_db( ultraBlah );

class MyClass
{
  var $holder;

  function MyClass( $someparam )
  {
     $this->holder = mysql_query( "select * from a_table" );
  }

  function get_object( )
  {
     return mysql_fetch_object( $this->holder );
  }
}

$o = new MyClass( moreblah );
$row = $o->get_object( );


$row never gets an object and PHP gives an error about $this->holder not being a valid MySQL resource.

This is very annoying since it destroyed the entire basis of my current project.  I'm assuming this is a bug.  At the very least, there should be some sort of option to disable the garbage collection for database stuff while inside a class.

If there is a way around it, I'd love to hear about it.

Also, as a side rant, it seems constructing objects is a very expensive process in terms of time.  That's another problem I ran into.  (Although that is probably not a bug so I'm not going to bother reporting it as one)

Otherwise, PHP4.0.1pl2 rocks the world.  :-)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2000-07-07 11:17 UTC] stas at cvs dot php dot net
Most probably, you don't set up connection right and/or your query doesn't work. 
When connection is set up right, it works for me.
Please try to do var_dump( $this->holder) in the first function and report what is it giving.
 [2000-07-24 09:09 UTC] stas@php.net
no feedback
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sun Jul 06 17:01:33 2025 UTC