|
Posted by Anonymous via the Cypherpunks Tonga Remailer on 11/15/05 23:30
Hi,
I'm building a simple Object Oriented CMS using PHP5
and the new object model (new to both). I'm looking
for some design advice on how best to integrate the
database class - which creates the db connection and
executes the sql queries. In my particular case,
I have 3 objects (classes) that I instantiate from
a given script (call it index.php). Each must have
access to the database. So, do I create a db connection
once and declare it 'global' in the various classes?
or do I create a db connection in each class - maybe
in the constructor? or is there some other practice
that's widely accepted? Any recommendations are
greatly appreciated.
<?php
// index.php
$dbconn = csite::DB();
$a = new cvisitor();
$b = new cvalid8r();
$c = new cnode();
... blah blah
?>
<?php
// cvisitor.php
class cvisitor {
public function __construct() {
}
public function __destruct() {
}
public function getVisitor() {
// open the db
global $dbconn;
... do the db stuff
?>
Thanks,
b
Navigation:
[Reply to this message]
|