Reply to simple example of how to use a db access class

Your name:

Reply:


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

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация