I’m wondering what the best practice would be if I wanted to create modules (classes) that are as framework agnostic as possible. For example, I have a module (a group of classes) to send out mailing messages, or a module to accept and manage patient registrations. I have clients who often have a web site or an online application and ask me to add some functionality to their existing system. Each of these applications have been based on a different framework so it would be useful for me to be able to reuse my classes in those applications regardless of the framework.
In most cases I am able to create classes that are pretty independent from the outside world, however the biggest problem is the database access. Each site/framework uses a different way of accessing the database, they have their own abstraction layers or wrapper functions or classes based either on PDO or mysqli. This makes it hard for my modules to be independent because in each case the interface for database access is different.
How would you go about this? Create a proxy class (db driver) that would sit between my module and the external system? I imagine it would be advisable to use the same database connection as the underlying system so as not to create another connection just to be independent in my programming style.