2016-04-06 7 views
0

私は現在、立ち往生しています..それはそれは数だときに出力することは容易ではありません配列として返すカウントメンバーを取得しようとするとメンバー数..アレイ出力数?

がここにコード

Member.php

があります

public function __construct() { $this->_pdo = DB::connect(); }

public function count() { 
    $this->_query = $this->_pdo->query("SELECT COUNT(*) FROM members"); 
    if(!$this->_query->error()) { 
     print_r($this->_query); 
    } 
    return false; 
} 

をdb.php

private function __construct() { 
    try { 
     $this->pdo = new PDO('mysql:host=' . Config::get('mysql/host') . ';dbname=' . Config::get('mysql/dbname'), Config::get('mysql/username'), Config::get('mysql/password')); 
    } catch(PDOException $e) { 
     die($e->getMessage()); 
    } 
} 

public static function connect() { 
    if(!isset(self::$_connect)) { 
     self::$_connect = new DB(); 
    } 
    return self::$_connect; 
} 

public function query($sql, $params = array()) { 
    $this->_error = false; 
    if($this->_query = $this->pdo->prepare($sql)) { 
     $x = 1; 
     if(count($params)) { 
      foreach($params as $param) { 
       $this->_query->bindValue($x, $param); 
       $x++; 
      } 
     } 

     if($this->_query->execute()) { 
      $this->_results = $this->_query->fetchAll(PDO::FETCH_OBJ); 
      $this->_count = $this->_query->rowCount(); 
     } else { 
      $this->_error = true; 
     } 
    } 
    return $this; 
} 

これを正しい方法で出力するにはどうすればよいですか?

答えて

1

データを取得する必要があります。

$this->_query->fetchColumn(); 
+0

これはすでに$ this - > _ pdo - > query()関数で行われています。 –

+0

すでにどこが完了していますか? – Federkun

+0

が更新されました。あなたが見るところでは、 'PDC :: query'メソッドではなく、' DbClass :: query'メソッドを呼び出さないと、 –