Example #1
0
 public static function get($new_connection = false)
 {
     if (!isset(self::$config)) {
         self::$config = server_get_config();
     }
     if (!db::$connection || $new_connection) {
         $db = new self(self::$config['db_server'], self::$config['db_username'], self::$config['db_password'], self::$config['db_database'], self::$config['db_port']);
         if (mysqli_connect_error()) {
             throw new Exception(sprintf('Could not connect to database server. Error received: %s', mysqli_connect_error()), MYSQL_CONNECT_ERROR);
         }
         if (!$db->set_charset('utf8')) {
             throw new Exception('Could not change MySQL character-set. Check your MySQL user credentials');
         }
         if (!$db->set_time_zone()) {
             throw new Exception('Could not change MySQL time-zone. Check your MySQL user credentials');
         }
         if (isset($config['mysql_big_selects']) && $config['mysql_big_selects'] === true) {
             if (!$db->enable_compat_mode()) {
                 throw new Exception('Could not change MYSQL compatbility options. Check your MySQL user permissions.');
             }
         }
         if ($new_connection) {
             return $db;
         }
         db::$connection = $db;
     }
     return db::$connection;
 }