DB.php 761 B

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: root
  5. * Date: 31.07.18
  6. * Time: 10:50
  7. */
  8. class DB
  9. {
  10. private static $instance;
  11. private $connection;
  12. private static $db_host = '127.0.0.1';
  13. private static $db_name = 'library';
  14. private static $db_user = 'root';
  15. private static $db_pass = 'root';
  16. private function __construct()
  17. {
  18. $this->connection = new PDO(
  19. 'mysql:host=' . self::$db_host .
  20. ';dbname=' . self::$db_name, self::$db_user, self::$db_pass);
  21. }
  22. public static function getConnection()
  23. {
  24. if (!self::$instance instanceof self) {
  25. self::$instance = new self();
  26. }
  27. return self::$instance->connection;
  28. }
  29. private function __clone()
  30. {
  31. }
  32. }