I am making a mysqli class for my website, but I'm stuck.
This is my class:
class Database {
private $mysqli = '';
private $params = '';
private $result = '';
function Database($hostname, $username, $password, $database) {
$this->mysqli = new mysqli($hostname, $username, $password, $database);
if ($this->mysqli->connect_errno) {
printf('Error #%s -> %s', $this->mysqli->connect_errno, $this->mysqli->connect_error);
exit;
}
}
public function setQuery($query) {
$this->result = $this->mysqli->prepare($query);
$this->params = array();
return $this;
}
public function setParam($type, $value) {
$this->params[$type] = $value;
return $this;
}
public function execute() {
$params = $this->params;
foreach ($params as $key => $value) {
$this->result->bind_param($key, $value);
}
$user = $this->result->result_metadata()->fetch_assoc();
echo $user['username'];
}
}
I'm using:
Core::$database->setQuery('SELECT * FROM habbo_characters WHERE id = ?')->setParam('i', 1)->execute();
But I got no output / empty string as output. What i'm doing wrong? The setParam function works correctly, it's not that. And it contains user with id 1 (the sql).