1234567891011121314151617181920212223242526272829303132333435363738394041 |
- <?php
- /**
- * Created by PhpStorm.
- * User: root
- * Date: 31.07.18
- * Time: 10:50
- */
- class DB
- {
- private static $instance;
- private $connection;
- private static $db_host = '127.0.0.1';
- private static $db_name = 'library';
- private static $db_user = 'root';
- private static $db_pass = 'root';
- private function __construct()
- {
- $this->connection = new PDO(
- 'mysql:host=' . self::$db_host .
- ';dbname=' . self::$db_name, self::$db_user, self::$db_pass);
- }
- public static function getConnection()
- {
- if (!self::$instance instanceof self) {
- self::$instance = new self();
- }
- return self::$instance->connection;
- }
- private function __clone()
- {
- }
- protected function __wakeup()
- {
- }
- }
|