Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Singleton Class Database used to connect to the database while only making one connection
- * @author Wesley Klop<wesley19097@gmail.com>
- */
- final class Database
- {
- /** @var PDO $dbh */
- private static $dbh;
- /** @var string $username */
- private static $username = '';
- /** @var string $password */
- private static $password = '';
- /** @var string $dsn */
- private static $dsn = "mysql:host=localhost;dbname=" . self::$username . ";charset=UTF8";
- /** @var array $options */
- private static $options = array(
- PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'utf8'",
- PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
- );
- /** @ignore */
- public function __construct()
- {
- }
- /** @ignore */
- public function __clone()
- {
- }
- /**
- * @return PDO $dbh database handle
- * @throws PDOException
- */
- public static function getInstance()
- {
- if (!(self::$dbh instanceof PDO)) {
- self::$dbh = new PDO(self::$dsn, self::$username, self::$password, self::$options);
- }
- return self::$dbh;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement