<?php
class Db {
public static $instance;
private $_mysqli,
$_query,
$_results = [],
$_count = 0;
public static function getInstance() {
if (self::$instance === null) {
self::$instance = new Db();
}
return self::$instance;
}
public function __construct() {
$this->_mysqli = new mysqli('localhost', 'root', '', 'loginapp');
if ($this->_mysqli->connect_error) {
die($this->_mysqli->connect_error);
}
}
public function query($sql) {
if ($this->_query = $this->_mysqli->query($sql)) {
while ($row = $this->_query->fetch_object()) {
$this->_results[] = $row;
}
$this->_count = $this->_query->num_rows;
}
return $this;
}
public function results() {
return $this->_results;
}
public function count() {
return $this->_count;
}
}
?>