Inheriting database connection in PHP OOP
- by vrode
My abstract class Database is made for database interaction and any child of this class (UserDatabase, ActionDatabase, EventDatabase) inherits its database connection which is defined as static.
`abstract class Database {
static $connection = mysql_connect( );
}
class UserDatabase extends Database {
...
public function __construct( ) {
$connection ? "connected" : "not connected";
$this-table = "users";
mysql_query( "FROM " . $this-table . " SELECT *" );
}
}
`
Does that mean, that my database connection is only set up and stored in memory once and passed on to subclasses as reference without being replicated for each instance?
Is this how you would implement you OOP-correct database interface?