成员计数.数组输出数字


member count.. Array output numbers?

我当前被卡住了。。

当试图获取成员计数时,它会以数组的形式返回,当它是一个数字时,输出就不那么容易了。。这是代码

成员.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;
}

如何以正确的方式输出?

您需要获取数据。

$this->_query->fetchColumn();