All pastes #978617 Raw Edit

tom

public php v1 · immutable
·published 2008-04-09 18:14 UTC
rendered paste body
 pdo_connect.php=================class PDOContainer{    public static $pdo = NULL;    public function __construct()    {        if (!self::$pdo)        {            PDOContainer::$pdo = new PDO(                'mysql:host='.DB_HOST.';dbname='.DATABASE,                DB_USER, DB_PASSWORD,                Array(PDO::ATTR_PERSISTENT => TRUE));        }    }} other_script.php==================require_once('pdo_connect.php');class SomeClass extends PDOContainer{    public function doSomething()    {        self::$pdo->prepare('SELECT * FROM my_table'); // they all share the same $pdo anyway    }}The moment an object of class SomeClass is created, the PDOContainer::$pdo will be initialized