I would like to read about your different strategies. For example, if you have a database with this tables:
- users
- posts
- comments
Do you use a only class for the database operations or do you use DB operations in every class (User, Post, Comment…)?
My strategy is to have these PHP classes:
- Item
- User extends Item
- Post extends Item
- Comment extends Item
- ItemSet implements Iterator
- UserSet implements Iterator
- etc…
Almost all the sql querying is done in Item class, but in User, Post and Comment class, the queries are built to be sent to Item class where the database connection is done and the query is executed.
Your strategy is good from OOP point of view, but consider DB-calls usually takes really much time. So using ADO (abstraction layer for databases) is ok, but too much abstraction is not.
So in my opinion – providing some abstraction for DB usage is ok, but ALWAYS consider performance.
Also some advice – take a look about table-locking related materials (to avoid races in your PHP application).
I recommend looking for some good example of existing open-source approach to this (e.g. Doctrine).