<?php
include 'Config.php';
include 'DB.php';
/*
$conf1 = Config::getInstance();
echo $conf1->getLanguage();
$conf2 = Config::getInstance()->setLanguage('en');
echo $conf1->getLanguage();
*/
$users = Db::getInstance()->query("SELECT * FROM users");
if ($users->count()) {
foreach ($users->results() as $user) {
echo $user->username . "<br>";
}
}
?>
<?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;
}
}
?>