Object Scope Question
Posted: Sun Mar 30, 2008 12:38 am
Guys, I am still a bit new to PHP objects and feel like I am tripping over myself.
I think this should be simple enough.
I want to make a database class to handle all DB activity.
I want to make a user session class to handle all session activity (mysql based).
I want to make a products class to handle all product functions.
I only want to open 1 database connection at the top of the page and close 1 database connection at the bottom of the page.
Both the user session and products class need to access db functionality in the db class. Am I correct in my thinking that if the session class and products class both extend the db class, that there will be 2 seperate db connections?
I would like to reference the db class from other classes without setting my connection resource to public. Can I do this?
Here is what I have and it works only with my db connection resource set to public.
Also, if someone could please confirm: The Ampersand before an object means to reference that object and not create a 2nd instance, is this correct?
I think this should be simple enough.
I want to make a database class to handle all DB activity.
I want to make a user session class to handle all session activity (mysql based).
I want to make a products class to handle all product functions.
I only want to open 1 database connection at the top of the page and close 1 database connection at the bottom of the page.
Both the user session and products class need to access db functionality in the db class. Am I correct in my thinking that if the session class and products class both extend the db class, that there will be 2 seperate db connections?
I would like to reference the db class from other classes without setting my connection resource to public. Can I do this?
Here is what I have and it works only with my db connection resource set to public.
Code: Select all
<?php
# Create a database object
$dbServer = new Database;
# Begin the User Session
$user = new User(&$dbServer);
?>