|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2000-07-07 11:17 UTC] stas at cvs dot php dot net
[2000-07-24 09:09 UTC] stas@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2026 The PHP GroupAll rights reserved. |
Last updated: Sun Mar 22 16:00:02 2026 UTC |
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. :-)