Hi Group,
I've got a small web interface, basically a link index with
different categories.I use different classes for HTML rendering,
category managing, link managing etcetera.
Now, most of these classes need DB access, but it's best to limit
the DB connections per requested page (no?). So I've got two ideas
here:
- I create a DB connection $maindbconn (object of class
DBConnection) in the main script, and make sure every class has its
own $dbconn class variable. In the class constructors, the main DB
connection is passed by reference to the class, so every class has
access to that one db connection.
- I create a DB connection $maindbconn in the main script, and in
every class function that needs it, I use "global $maindbconn;".
Now, which approach seems best to you experts out there? And why?
Thanks in advance,
Bobo