I have 2 classes, Base.class.php and MyClass.class.php. MyClass extends Base. Base has a var $link which is initialised as a mysql database connection when the constructor is called.
Base also has a function destroy() which closes the link.
Each page uses $myClass = new MyClass(); thereby initialising $link in Base. At the end of each page I call $myClass->destroy() to close the $link in the parent class. This works OK.
The problem is that when I instantiate AnotherClass.class.php which also extends Base, and is also used in the same pages, that when I call $anotherClass->destroy() before I call $myClass->destroy() it closes the $link in *both* $myClass *and* $anotherClass. This causes an error because $myClass should still be open for use.
What is $link in each Base class? Is it a reused connection? Is it an existing open connection? Is it a page scope connection? How should I get around this? Using true on the mysql open connection? Or never using destroy()?
2006-11-08
19:41:50
·
2 answers
·
asked by
a11st4rc
2
in
Computers & Internet
➔ Programming & Design