This is my code:
class DB {
static $instance;
function get() {
if (self::$instance === null) {
self::$instance = new PDO('mysql:host=localhost;dbname=forum', 'root', 'root');
}
return self::$instance;
}
function getAllUsers() {
$users = array();
$sql = "SELECT * FROM users";
foreach (self::get()->query($sql) as $row) {
$users[] = new User($row);
}
return $users;
}
}
And now I'm calling the getAllUsers function in here:
class App {
function showUsers() {
$users = DB::getAllUsers();
}
Except its giving me an error:
Warning: Invalid argument supplied for foreach()
When I'm doing var_dump
on self::get
im getting a bool(false)
Can someone tell me what I'm doing wrong?