所以我创建了一个数据库类来处理我所有的数据库请求。一切都通过构造函数,它应该返回值。
课是这样的
<?php
class Database {
/**
* This array holds all of the configuration settings for the database
* @var array
*/
private $config = array(
'username' => '',
'password' => '',
'host' => '',
'database' => ''
);
/**
* Holds the parameters passed to the class
* @var mixed
*/
private $parameters;
/**
* Database Handler
* @var [type]
*/
private $DBH;
/**
* Class constructor
* @param [type] $action [description]
* @param [type] $parameters [description]
*/
public function __construct($action, $parameters){
$this->parameters = $parameters;
$this->DBH = new PDO("mysql:host=".$this->config['host'].";dbname=".$this->config['database'], $this->config['username'], $this->config['password']);
return $this->$action();
}
private function query(){
$STH = $this->DBH->prepare($this->parameters);
$STH->execute();
$result = $STH->fetchColumn();
echo "<br><br>RESULT:".$result."<br><br><br>";
echo "<br><br>RESULT:".empty($result)."<br><br><br>";
return (empty($result)) ? FALSE : TRUE;
}
}
我删除了所有问题的功能。它旨在返回真或假。相反,我调用时的返回值$result = new Database('query', $query);
是一个包含大量数据的对象
知道我做错了什么吗?