getAttribute(PDO::ATTR_SERVER_INFO) == 'MySQL server has gone away') { // On most recent versions of PHP the call to getAttribute() on a lost connection will // throw an exception anyway, but just in case it doesn't we'll throw one. See // https://stackoverflow.com/questions/21595402/php-pdo-how-to-get-the-current-connection-status throw new \Exception('MySQL server has gone away'); } } catch (\Exception $e) { try { $db_obj = DBFactory::create( $dbsys, $db_host, $db_login, $db_password, $db_database, (bool)$db_persist, $db_port, $db_options ); } catch (\Exception $e) { trigger_error($e->getMessage(), E_USER_WARNING); Errors::fatalError(get_vocab('fatal_db_error')); } } return $db_obj; } // Returns the db schema version as recorded in the database. If there is no version // recorded then returns 0. If $local is true then the local db schema version is returned. function db_schema_version(DB $handle, bool $local=false) : int { if ($handle->table_exists(_tbl('variables'))) { $sql_params = [':variable_name' => ($local) ? 'local_db_version' : 'db_version']; $sql = "SELECT variable_content FROM " . _tbl('variables') . " WHERE variable_name=:variable_name"; $result = $handle->query1($sql, $sql_params); } else { // Default version is 0, before we had schema versions $result = 0; } return max($result, 0); }