PHP OOP design question
| From: | Joseph Szobody | Date: | Tue, 04 Mar 2003 13:24:04 +0000 |
| Subject: | PHP OOP design question | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-138096@lists.php.net to get a copy of this message | ||
I have several web projects that are all database driven. I have recently been diving into OOP, and
rewriting a lot of procedural code in OOP. I have a design question about handling the MySQL
connection.
I have a mysql() class which handles all my queries, automatic inserts/updates, etc. Just about
every other class will use the mysql() class at some point.
Should I....
1) Make every class extend mysql(), so that they all have direct access to the db functions
2) Create a new mysql object inside of each class.
3) Only create the mysql object at the script level, and pass in the object to the other classes.
I.e.:
// Create the db object
$mysql = new mysql();
Now create whatever other objects I need, passing in mysql as an argument.
$job = new job($mysql);
4) Some other idea?
Thanks for any help,
Joseph