08-23-2009, 09:48 PM
|
#4 (permalink)
|
|
La Vida es Sueño
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
|
As you've already identified a solution, we might as well stick to it. That being the singleton pattern. This would work like so. With the following database class:
php Code:
class Database { private static $m_pInstance; /** * @return Database */ public static function getInstance () { if (! isset(self:: $m_pInstance)) { self:: $m_pInstance = new self (); } return self:: $m_pInstance; } public function query ($szSQL) { printf("Executing query: %s<br />", $szSQL); }}
And then we can use it like so from any other class we wish:
php Code:
class MyClass { public function __construct() { Database:: getInstance()-> query('SELECT * FROM myTable'); }}new MyClass ();
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
|
|
|