Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Database
- {
- private $_connection;
- private static $_instance;
- private $_host = "IP";
- private $_username = "USERNAME";
- private $_password = "PASS!";
- private $_database = "DATABASENAME";
- public static function getInstance()
- {
- if(!self::$_instance)
- {
- self::$_instance = new self();
- }
- return self::$_instance;
- }
- private function __construct()
- {
- $this->_connection = new mysqli($this->_host, $this->_username, $this->_password, $this->_database);
- if(mysqli_connect_error())
- {
- trigger_error("Failed to connect to MySQL: " . mysql_connect_error(), E_USER_ERROR);
- }
- }
- private function __clone() { }
- public function getConnection()
- {
- $this->_connection->query('SET CHARACTER SET utf8');
- return $this->_connection;
- }
- }
- <?php
- require_once('database.php');
- $db = Database::getInstance();
- $db = $db->getConnection();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement