09-25-2009, 10:01 AM
|
#10 (permalink)
|
|
That guy
Join Date: Sep 2009
Location: San Antonio, TX
Posts: 25
Thanks: 0
|
Great
Great tutorial. It actually looks a lot like the way I did my singleton pattern.. lol
Here it is:
PHP Code:
class Config
{
const host = "localhost";
const user = "root";
const pass = "pass";
const name = "name";
}
final class Singleton extends Config
{
protected static $connection;
protected static $database = null;
protected function Singleton () { }
protected function __clone () { }
static function Prepare()
{
self::$connection = new mysqli
(
parent::host,
parent::user,
parent::pass,
parent::name
);
if (mysqli_connect_errno())
{
printf
(
"Connection Error: %s\n ", mysqli_connect_error()
);
} else { echo "Databse resource found."; }
}
public static function Instance()
{
if (!isset(
self::$database)) {
self::$database = self::Prepare();
}
return self::$database;
}
}
$instance = Singleton::Instance();
|
|
|
|