2016-10-21 12 views
0

に私は大きな問題を持っている\:

私は」フレームワークなしで新しいWebAppを作成します。 私はxamppと崇高なテキストを使用しています。 私はこの問題をどのように解決できるのか分かりません。

私をdb.phpは、私はなぜエラーが来ている?多分

require_once 'core/init.php'; 

// echo Config::getir('mysql/host'); 
// calismadi $kullanici = DB::baglan() -> query("SELECT kullanici_adi FROM uye WHERE kullanici_adi = ?", array('oguzhan')); 
$kullanici = DB::baglan()->getir('uye', array('kullanici_adi', '=', 'oguzhan')); 

if ($kullanici->hatalar()) { 
    echo 'Kullanıcı yok'; 
}else{ 
    echo 'Var'; 
} 

をロードしています私のindex.phpで

class DB{ 

    private static $_baglan = null; 
    private $_pdo, 
      $_query, 
      $hatalar = false, 
      $sonuc, 
      $_sayac = 0; 

      public function __construct(){ 
       try{ 

        $this -> _pdo = new PDO('mysql:host=' . Config::getir('mysql/host') . ';dbname=' . Config::getir('mysql/db'), Config::getir('mysql/kullanici_adi'), Config::getir('mysql/sifre')); 
        // echo 'baglandi'; 
       }catch(PDOException $e){ 
        die($e->getMessage()); 
       } 
      } 

      public static function baglan(){ 
       if (!isset(self::$_baglan)) { 
        self::$_baglan = new DB(); 
        // echo 'baglandi'; 
       } 
       return self::$_baglan; 
      } 

      public static function query($sql, $parametre=array()){ 

       $this->_hatalar = false; // line 32 
       if ($this->_query = $this->_pdo->prepare($sql)) { 
        $x = 1; 
        if (count($parametre)) { 
         foreach ($parametre as $param) { 
          $this->_query->bindValue($x, $parametre); 
          $x++; 
         } 
        } 
        if ($this->_query->execute()) { 
         $this->sonuc=$this->_query->fetchAll(PDO::FETCH_OBJ); 
         $this->_sayac=$this->_query->rowCount(); 
        }else{ 
         $this->_hatalar=true; 
        } 
       } 
       return $this; 
      } 

      public function eylem($eylem, $tablo, $where=array()){ 

       if (count($where)===3) { 

        $operatorler = array('=', '<', '>', '>=', '<='); 
        $alan = $where[0]; 
        $operator = $where[1]; 
        $deger = $where[2]; 
        if (in_array($operator, $operatorler)) { 
         $sql = "{$eylem} FROM {$tablo} WHERE {$alan} {$operator} ?"; 
         if (!$this->query($sql, array($deger))->hatalar()) { 
          return $this; 
         } 
        } 
       } 
       return false; 
      } 

      public function getir($tablo, $where){ 
       return $this->eylem('SELECT *', $tablo, $where); 
      } 
      public function sil($tablo, $where){ 
       return $this->eylem('DELETE', $tablo, $where); 
      } 

      public function hatalar(){ 
       return $this->hatalar(); 
      } 

} 

を書かれた方法の例

答えて

0

queryメソッドからstaticキーワードを削除すると、問題を解決できます。

$thisは、インスタンス化されたオブジェクトに対してのみ使用できます。 selfまたはstaticはクラス自体を参照し、クラスのインスタンス化されたオブジェクトは参照しません。この例では

class Person{ 

    private $name; 

    public function __construct(string $name){ 
     $this->name = $name; 
    } 

    public function greet(){ 
     echo 'Hello my name is ' . $this->name; 
    } 
} 

$person = new Person('Thomas'); 
$person->greet(); // prints 'Hello my name is Thomas' 

$this作品は、我々は最初のnewキーワードを使用してオブジェクトをインスタンス化しているため。 methodsvariablesstaticキーワードも使用していません。

selfおよびstaticは、class自体でのみ動作し、objectではインスタンス化しません。 selfstaticis explained hereの違い。ここ

classmethodsvariablesstaticキーワードの使用に気付く、self使用例である:

class StaticClass{ 
    private static $variable = ''; 
    public static function change(string $variable){ 
     self::$variable = $variable; 
    } 
    public static function print(){ 
     echo self::$variable; 
    } 
} 

StaticClass::change('Hello'); 
StaticClass::print(); // print 'Hello' 
関連する問題