If I change my Default_Database name to MySQLi_Database and then extend the class like so:
[Example 1]
Code: Select all
class Default_Database extends MySQLi_Database {
private function _connect () {
self::$_db->real_connect('127.0.0.1', 'root', '*****', '*****');
}
}[Example 2]
Code: Select all
self::$_db->real_connect('127.0.0.1', 'root', '*****', '*****');No matter what is used here there is going to be a problem, passing no parameters will attempt a connection based default values and passing wrong values will cause errors, either way we either connect to 2 different databases when not required, connect to the same database twice (if persistent connections are not enabled), or plain and simply get lots of errors.
As the MySQLi_Database class has lots of useful methods that return values, I want this functionality to be easily extended should somebody need to connect to 2 different databases like in [Example 1] but I want to stop people creating an instance of MySQLi_Database itself. Is this at all possible?
Cutting a long story short, I want to be able to extend a class that is restricted so that the only way it can be used is when it is extended.