Something similar to:-
PHP Code:
<?php
class Database
{
private static $oInstance = null;
public static function getInstance()
{
if(is_null(self::$oInstance))
{
self::$oInstance = new Database( 'localhost', 'username', 'password', 'database' );
}
return self::$oInstance;
}
private function __construct( $sHost, $sUsername, $sPassword, $sDatabase, $iPort = 3306 )
{
try{
self::$oInstance = new mysqli( $sHost, $sUsername, $sPassword, $sDatabase, $iPort );
return;
}catch(Exception $oException){
throw new Exception($oException->getMessage());
return;
}
}
}
class CMS
{
protected $oDatabase;
public function __construct()
{
$this->oDatabase = Database::getInstance();
}
}
class Users extends CMS
{
public function getUserByID( $iID )
{
$oResult = $this->oDatabase->query("SELECT name,email FROM users WHERE id = $iID LIMIT 1;");
// Do Stuff.
}
}
?>
I hope I'm making sense, or should I say, talking sense!
Bookmarks