Merhaba arkadaşlar, localhostta sorunsuz çalışıyor fakat hosta kurmaya çalıştığımda bu şekilde hata alıyorum.

HATA VAR : SQLSTATE[HY000] [2002] Connection refused
Fatal error: Call to a member function prepare() on a non-object in /home/mevyecom/public_html/settings.php on line 7

internette araştırdım settings.php dosyamı bu şekilde;

<?php


require_once "config/config.php";

$baglanti->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sth = $baglanti->prepare("SELECT * FROM custom");
$sth->execute();
$result = $sth->fetchAll(PDO::FETCH_ASSOC);
$title = $result[0]['title'];
$description = $result[0]['description'];
$keyword = $result[0]['keyword'];
$contract = $result[0]['contract'];


$baglanti->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sth = $baglanti->prepare("SELECT * FROM notice");
$sth->execute();
$result = $sth->fetchAll(PDO::FETCH_ASSOC);

$login_notice = $result[0]['login_notice'];
$service_notice = $result[0]['service_notice'];
$api_notice = $result[0]['api_notice'];

?>
config bölümü;

<?php


try{

$baglanti=new PDO("mysql:host=localhost;dbname=-","-","-");
$baglanti->exec("SET NAMES utf8");


}catch (PDOException $h) {

$hata=$h->getMessage();

echo "<b>HATA VAR :</b> ".$hata;

}

 ?>
GÜNCEL ---

Config;

<?php

class DB {
    private $baglanti;
    public function __construct() {
        $this->baglanti =new PDO("mysql:host=-;dbname=-","-","-");
    }
    public function myfunction() {
      
    }
}

 ?>
Settings dosyam. Bu şekilde index geliyor fakat sadece settings dosyamda ki php kodları çalışıyor. Bu işlemi config'de myfunction iiçinde yapınca yine aynı hatayı alıyorum.
Config dosyamda global olarak tanımlayıp bütün php, veri tabanı bağlantılarını nasıl kullanılabilir yapabilirim?
<?php
function myfunction() {
require_once 'config/config.php';

$baglanti->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sth = $baglanti->prepare("SELECT * FROM custom");
$sth->execute();
$result = $sth->fetchAll(PDO::FETCH_ASSOC);
$title = $result[0]['title'];
$description = $result[0]['description'];
$keyword = $result[0]['keyword'];
$contract = $result[0]['contract'];


$baglanti->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sth = $baglanti->prepare("SELECT * FROM notice");
$sth->execute();
$result = $sth->fetchAll(PDO::FETCH_ASSOC);

$login_notice = $result[0]['login_notice'];
$service_notice = $result[0]['service_notice'];
$api_notice = $result[0]['api_notice'];

}
?>