. */ require_once(ROOT_DIR . "/helpers/config.php"); /** * mysqli wrapper */ class uDb extends mysqli { /** * Singleton instance * * @var mysqli Object instance */ protected static $instance; /** * Table names * * @var array Array of names */ protected static $tables; /** * Private constuctor * * @param string $host * @param string $user * @param string $pass * @param string $name */ private function __construct($host, $user, $pass, $name) { parent::__construct($host, $user, $pass, $name); if ($this->connect_error) { if (defined('headless')) { header("HTTP/1.1 503 Service Unavailable"); exit; } die("Database connection error (" . $this->connect_error . ")"); } $this->set_charset('utf8'); } /** * Returns singleton instance */ public static function getInstance() { if (!self::$instance) { $config = new uConfig(); self::$instance = new self($config::$dbhost, $config::$dbuser, $config::$dbpass, $config::$dbname); self::$tables = []; $prefix = preg_replace('/[^a-z0-9_]/i', '', $config::$dbprefix); self::$tables['positions'] = $prefix . "positions"; self::$tables['tracks'] = $prefix . "tracks"; self::$tables['users'] = $prefix . "users"; } return self::$instance; } /** * Get full table name including prefix * * @param string $name Name * @return string Full table name */ public function table($name) { return self::$tables[$name]; } } ?>