Probably a silly question, I have many classes in PHP with this template:
class SomeTable {
private $db;
private $prefix;
private $tbl_name;
function __construct($db, $tbl_name) {
$this->db = $db;
$this->prefix = $db->tblPrefix();
$this->tbl_name = $tbl_name;
$this->install();
}
private function install() {
$sql = "CREATE TABLE IF NOT EXISTS...";
$this->db->query($sql, null);
}
// query functions
...
}
- I have one of these classes to represent each table in the database.
- The 3 private variables at the top must be available in each class, and they are set in the constructor.
- The constructor is the same for every class.
- The
install()function is different for every class because it is used to create the database table. (I like to keep it here because I can keep looking back at it while I'm writing/editing queries).
Do I then create an abstract class with the 3 variables, constructor, empty install() function and implement it in each class? Will it work the same for me?
I'm sorry if it's a dumb question, I've really never used classes/inheritance before in PHP.