2016-12-18 6 views
0

エラーの場所を特定できません。キャッチ可能な致命的なエラー:クラスPDOのオブジェクトを文字列に変換できませんでした。

キャッチできる致命的なエラー:私は取得していますエラーは、このですpostClass.inc:クラスPDOのオブジェクトは、ライン14

ファイルにpostClass.inc.php内の文字列に変換することができませんでした。 PHP

<?php 

include ('connect.inc.php'); 

class SimplePosts { 

    private $database; 
    private $sqlStatement; 
    private $queryColumn; 
    private $query; 
    private $result; 

    public function __construct($database, $column) { 
     $this->$database = $database; 
     $this->buildQuery($column); 
     $this->query = $this->$database->prepare($this->sqlStatement); 
     $this->query->execute(); 
    } 

    private function buildQuery($column) { 
     switch($column) { 
      case 'id': 
       $this->queryColumn = 'id'; 
       break; 
      case 'title': 
       $this->queryColumn = 'title'; 
       break; 
      case 'content': 
       $this->queryColumn = 'content'; 
       break; 
      case 'user_id': 
       $this->queryColumn = 'user_id'; 
       break; 
      default: 
       echo "'$column' is not a valid column"; 
     } 
     $this->sqlStatement = "SELECT * FROM posts ORDER BY $this->queryColumn"; 
    } 

    public function getPost() { 
     try { 
      $this->result = $this->query->fetch(PDO::FETCH_ASSOC); 
      return $this->result; 
     } catch (PDOException $e) { 
      echo "Error: " . $e->getMessage() . "<br />"; 
      echo "Unable to retrieve results <br>"; 
     }  
    } 

    public function id() { 
     echo $this->result['id']; 
    } 

    public function title() { 
     echo $this->result['title']; 
    } 

    public function content() { 
     echo $this->result['content']; 
    } 

    public function userId() { 
     echo $this->result['user_id']; 
    }  

} 

$test = new SimplePosts($database, 'id'); 

var_dump($test); 

?> 

すべての援助をいただければ幸いです。

答えて

2

スペル:

$this->$database = $database;

$this->database = $database;

+0

@rawlazする必要があり、親愛なる神は、私は私がそれを逃す可能性がどのように....このコードで盲目の自分を見つめてきました。..あなたに親切な/ありがとうございます。 –

関連する問題

 関連する問題