Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace Core;
- use \PDO;
- class Database
- {
- private $instance = null;
- private $username;
- private $password;
- private $server;
- private $dbname;
- public function __construct($username, $password, $server, $dbname)
- {
- $this->username = $username;
- $this->password = $password;
- $this->server = $server;
- $this->dbname = $dbname;
- }
- public function getInstance()
- {
- if ($this->instance == null) {
- $this->createInstance();
- }
- return $this->instance;
- }
- private function createInstance() {
- $this->instance = new PDO("mysql:host={$this->server};dbname={$this->dbname};charset=utf8", $this->username, $this->password);
- $this->instance->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement