So I made a database class to handle all of my database requests. Everything goes through the constructor and it should return values.
The class is so
<?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;
}
}
I removed everything bar the function giving issues. It is meant to return true or false. Instead the return value when I call $result = new Database('query', $query); is an object with a ton of data
Any idea what I have done wrong?
return !empty($result);would suffice.