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;
}
如何以正確的方式輸出?
這已經在$ this - > _ pdo-> query()函數中完成了。我可以做兩次嗎? –
哪裏已經完成? – Federkun
更新了這個問題,你可以看到那裏=) –