Advertisement
Guest User

Untitled

a guest
Sep 26th, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. <?php
  2. class ConnectionHandler
  3. {
  4. private static $connection = null;
  5. private function __construct() {}
  6. public static function getConnection()
  7. {
  8. if (self::$connection === null) {
  9. $config = require('config.php');
  10. $host = $config['database']['host'];
  11. $username = $config['database']['username'];
  12. $password = $config['database']['password'];
  13. $database = $config['database']['database'];
  14. self::$connection = new MySQLi($host, $username, $password, $database);
  15. if (self::$connection->connect_error) {
  16. $error = self::$connection->connect_error;
  17. throw new Exception("Verbindungsfehler: $error");
  18. }
  19. self::$connection->set_charset('utf8');
  20. }
  21. return self::$connection;
  22. }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement