error) die('Failed to connect to database.'); $interface->setErrorHandler(['DB', 'errorHandler']); $interface->query('SET NAMES ?', 'utf8'); if ($options['prefix']) $interface->setIdentPrefix($options['prefix']); // disable STRICT_TRANS_TABLES and STRICT_ALL_TABLES off. It prevents usage of implicit default values. if ($idx == DB_AOWOW) $interface->query("SET SESSION sql_mode = 'NO_ENGINE_SUBSTITUTION'"); // disable ONLY_FULL_GROUP_BY (Allows for non-aggregated selects in a group-by query) else $interface->query("SET SESSION sql_mode = ''"); self::$interfaceCache[$idx] = &$interface; self::$connectionCache[$idx] = true; } public static function errorHandler($message, $data) { if (!error_reporting()) return; $error = "DB ERROR:

\n\n
".print_r($data, true)."
"; echo CLI ? strip_tags($error) : $error; exit; } public static function getDB($idx) { return self::$interfaceCache[$idx]; } public static function isConnected($idx) { return isset(self::$connectionCache[$idx]); } public static function isConnectable($idx) { return isset(self::$optionsCache[$idx]); } private static function safeGetDB($idx) { if (!self::isConnected($idx)) self::connect($idx); return self::getDB($idx); } /** * @static * @return DbSimple_Mysql */ public static function Characters($realm) { if (!isset(self::$optionsCache[DB_CHARACTERS.$realm])) die('Connection info not found for live database of realm #'.$realm.'. Aborted.'); return self::safeGetDB(DB_CHARACTERS.$realm); } /** * @static * @return DbSimple_Mysql */ public static function Auth() { return self::safeGetDB(DB_AUTH); } /** * @static * @return DbSimple_Mysql */ public static function World() { return self::safeGetDB(DB_WORLD); } /** * @static * @return DbSimple_Mysql */ public static function Aowow() { return self::safeGetDB(DB_AOWOW); } public static function load($idx, $config) { self::$optionsCache[$idx] = $config; } } ?>