Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Database
- {
- private $conn;
- private static $instance = null;
- private $host = 'localhost';
- private $db = 'test_db';
- private $username = 'test';
- private $password = 'test';
- public static function getInstance()
- {
- if (is_null(static::$instance)) {
- static::$instance = new static;
- }
- return static::$instance;
- }
- private function __construct()
- {
- try {
- $this->conn = new PDO('mysql:host=' . $this->host . ';dbname=' . $this->db, $this->username, $this->password);
- $this->conn->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ);
- } catch (\PDOException $e) {
- die('Unable to connect to database:' . $e->getMessage());
- }
- }
- private function __clone() {}
- private function __wakeup() {}
- public function getConnection()
- {
- return $this->conn;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement