OK, this is just a quick question and I might take some slack for this but I’m just looking for a little guidance as I am completely self taught. I do a lot of reading and try to do a lot of building–I’d say I’m coming into a nice intermediate stage of php, mysql, and web knowledge in general–by no means advanced or overly confident–still learning.
I’m really trying to tackle OOP in PHP and so I want to create a good lean database wrapper for MySQL, just MySQL, I’m most comfortable with MySQL and I dont see any reason to use any other database. I dont want to create any sort of portability in the design–I want it to be specific to my database; so I dont want to use PDO.
So the question I have as of right now in the beginning is should I create a class that EXTENDS mysqli and then have create model classes for my database tables that extend that base database class? so class->child = mysqli->DbBase->UsersModel ? This would require a lot of $this statements inside the class, would it not?
Or should I instantiate a mysqli class and pass it to DbBase?
Classes kind of represent things in the real world (or even imaginary “things”), right? An instance of a DB represents a connection to that db. Has a model something in common with a database connection? Not really. I would suggest to include instances of your database class in those models classes you’re going to write, because a model uses a database connection to access it’s data but is not a kind of database connection.
Concerning Mysqli <-> DBClass: That really depends on what you’re trying to achieve with that DBClass – does it extend Mysqli with some extra functions or anything? If it doesn’t, don’t use inheritance there, otherwise you can use it.
A very basic example, just to give you the idea: (it is actually a simplified but definitely not complete version of the ActiveRecord pattern)
Usage: