Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class DBConnect {
- private static $_singleton;
- private $_connection;
- private $DB_USERNAME = 'root';
- private $DB_PASSWORD = '';
- private $DB_HOST = 'localhost';
- /**
- * Establish a connection to the database
- */
- private function __construct() {
- $this->_connection = new PDO("mysql:host=$this->DB_HOST;dbname=artdb", $this->DB_USERNAME, $this->DB_PASSWORD);
- $this->_connection->exec("SET CHARACTER SET utf8");
- }
- /**
- * Get an instance of this class
- * @return Connection a connection instance
- */
- public static function getInstance() {
- if (is_null(self::$_singleton)) {
- self::$_singleton = new DBConnect();
- }
- return self::$_singleton;
- }
- /**
- * Returns the PDO database connection handler
- * @return PDO database handler
- */
- public function getHandler() {
- return $this->_connection;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement