From a4eb37c3dc5e8952d95c269190b88a9b6d36b5fc Mon Sep 17 00:00:00 2001 From: Bartek Fabiszewski Date: Thu, 17 Aug 2017 17:19:47 +0200 Subject: [PATCH] Initialize table names in separate method --- helpers/db.php | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/helpers/db.php b/helpers/db.php index 206a527..2504bd6 100644 --- a/helpers/db.php +++ b/helpers/db.php @@ -44,9 +44,11 @@ * @param string $user * @param string $pass * @param string $name + * @param int $port + * @param string $socket */ - public function __construct($host, $user, $pass, $name) { - parent::__construct($host, $user, $pass, $name); + public function __construct($host, $user, $pass, $name, $port = null, $socket = null) { + @parent::__construct($host, $user, $pass, $name, $port, $socket); if ($this->connect_error) { if (defined('headless')) { header("HTTP/1.1 503 Service Unavailable"); @@ -55,19 +57,28 @@ die("Database connection error (" . $this->connect_error . ")"); } $this->set_charset('utf8'); + $this->initTables(); + } + + /** + * Initialize table names based on config + */ + private function initTables() { + self::$tables = []; + $prefix = preg_replace('/[^a-z0-9_]/i', '', uConfig::$dbprefix); + self::$tables['positions'] = $prefix . "positions"; + self::$tables['tracks'] = $prefix . "tracks"; + self::$tables['users'] = $prefix . "users"; } /** * Returns singleton instance + * + * @return object Singleton instance */ public static function getInstance() { if (!self::$instance) { self::$instance = new self(uConfig::$dbhost, uConfig::$dbuser, uConfig::$dbpass, uConfig::$dbname); - self::$tables = []; - $prefix = preg_replace('/[^a-z0-9_]/i', '', uConfig::$dbprefix); - self::$tables['positions'] = $prefix . "positions"; - self::$tables['tracks'] = $prefix . "tracks"; - self::$tables['users'] = $prefix . "users"; } return self::$instance; }