Inheriting database connection in PHP OOP

Posted by vrode on Stack Overflow See other posts from Stack Overflow or by vrode
Published on 2010-05-13T14:12:59Z Indexed on 2010/05/13 14:14 UTC
Read the original article Hit count: 195

Filed under:
|
|

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?

© Stack Overflow or respective owner

Related posts about php

Related posts about static