• 12-04-2018, 06:12:36
    #1
    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'];
    
    }
    ?>
  • 12-04-2018, 09:34:59
    #2
    Üyeliği durduruldu
    Godaddy mi host?
  • 12-04-2018, 12:05:43
    #3
    @Hasidluu; hayir siberdizayn kullaniyorum
  • 12-04-2018, 23:53:20
    #4
    Üyeliği durduruldu
    Mehmetmasa adlı üyeden alıntı: mesajı görüntüle
    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'];
    
    }
    ?>
    Bak şimdi güncel config dosyanda DB classı tanımlamışsın ve private bir değişken atamışsın. Bu değişken DB classı dışında kullanılamaz. Configi eski haline getir. Eski halinde yazdığın veritabanı bilgileri yanlış büyük ihtimal kodlarda sorun göremedim.
  • 13-04-2018, 05:57:14
    #5
    @Hasidluu; hocam yeni yaptığım DB bağlantısında aynı veri tabanı bilgileri ile bağlantı sağlanıyor. Veri tabanı bilgilerinde sorun yok.
    Sorunu hala çözemedim güncell



    Konu guncel
  • 15-04-2018, 13:13:43
    #6
    güncel