[READ-ONLY] Mirror of https://github.com/andrioid/travian.scrolls.org. Retired project. I got a bit overly engaged in an online game called Travian.
944 B
36 lines
1<?
2
3// Singleton class for Database access
4
5final class Database {
6 static private $instance; // Singleton instance
7 public $mysql;
8
9 private function __construct() {
10 global $Config;
11 // Database
12 @$this->mysql = new mysqli($Config['mysql_host'], $Config['mysql_user'], $Config['mysql_password'], $Config['mysql_db']);
13 if ($this->mysql->connect_error) {
14 $error = sprintf("Database connection failed (%d): %s", $this->mysql->connect_errno, $this->mysql->connect_error);
15 $friendlyError = sprintf("Database connection failed");
16 throw new SystemException('db_failed', $error);
17 }
18 $this->mysql->set_charset('utf8'); // Everything should be in UTF8
19 }
20
21 static public function getInstance() {
22 global $Node;
23 if (!isset(self::$instance)) {
24 self::$instance = new Database();
25 }
26 return self::$instance;
27 }
28 static public function isInstance() {
29 if (!isset(self::$instance)) {
30 return false;
31 }
32 return true;
33 }
34}
35
36?>