Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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();
Add Comment
Please, Sign In to add comment