What is the best practice?
- From: Ralphz <ralphzajac@xxxxxxxxxxxxx>
- Date: Sat, 23 Feb 2008 01:36:28 GMT
Hi
I have many classes that use database connections to fetch data and manipulate on it. I also have database abstraction class that is handling all the database queries and so forth.
Usually all my classes take instantiated database object as the first parameter to constructor so they know what database to use:
public function __constructor(Database $db, $var1, $var2){
if($db->is_connected()){
// construct class
} else {
throw new Exception('Bla bla bla');
}
}
then in the script i do:
try{
$db = DB::create_DB($DB_settings);
$u = new theOtherClass($db, $var1, $var2);
} catch (...)
It works great if the class uses only one database connection. I establish connection pass the object to "theOtherClass" and I'm happy :)
Now I'm designing class that will be aggregating at least 5 other classes that might use different databases.
I don't want to create 5 objects and then pass them to this class' constructor. So I'm looking for better way to do it.
Any ideas?
Ralph
PS: I was thinking of passing array with all the settings to the constructor and then creating objects internally based on info in an array. But don't like the idea so much.
.
- Prev by Date: Re: Path getting messed up - cannot find a file
- Next by Date: Re: Path getting messed up - cannot find a file
- Previous by thread: Path getting messed up - cannot find a file
- Next by thread: PHP Reference Guide
- Index(es):
Relevant Pages
|