Stack Exchange
collecting mysql query result from table
I need to query a table in an associative array using singleton database connection and im getting error,
Notice: Undefined variable: id in C:\xampp\htdocs\SOBCASHIER\resources\templates\loginmodel.php on line 10
Notice: Undefined variable: name in C:\xampp\htdocs\SOBCASHIER\resources\templates\loginmodel.php on line 10
Notice: Undefined variable: loc in C:\xampp\htdocs\SOBCASHIER\resources\templates\loginmodel.php on line 10
Warning: mysqli_stmt::fetch() expects exactly 0 parameters, 3 given in C:\xampp\htdocs\SOBCASHIER\resources\templates\loginmodel.php on line 10
Notice: Array to string conversion in C:\xampp\htdocs\SOBCASHIER\resources\templates\loginmodel.php on line 12
Array
my db.config.php
define ('HOST','localhost');
define ('USER','garodamas_mon');
define ('PASSWORD','r0d4m45');
define ('DATABASE','garodamas_cashrcv');

class Database{
    private $DBH;
    private static $singleton;
    protected function __construct(){
        $this->DBH=new mysqli(HOST,USER,PASSWORD,DATABASE);
    }
    public static function instance(){
        if (!(self::$singleton instanceof self)) {
            self::$singleton = new self();
        }
        return self::$singleton;
    }
    public static function get(){
        return self::instance()->DBH;
    }
    private function __wake(){}
    private function __clone(){}
}

and my loginmodel.php
<?php
require_once '../db.config.php';


$get=Database::get()->prepare('SELECT user_id, user_name, user_dept FROM mst_user');
$get->execute();
$row = array();

$get->fetch($id, $name, $loc);
        while($get->fetch()){
            print($row);
        }

i dont know where my error is. mst_user has 3 columns. Please help me.. thanks

SHOW * create problem it would be SELECT *

The prepare() statement is returning false, because there is an error. 

mysqli_prepare() returns a statement object or FALSE if an error occurred.

Try 
new mysqli(HOST,USER,PASSWORD,DATABASE)->prepare('badsql')->execute();

And then fix the badsql.

 require_once '../db.config.php';

$get=Database::get()->prepare('SELECT user_id, user_name, user_dept FROM mst_user');
$get->execute();  


with PDO:

while ($row = $get->fetch(PDO::FETCH_NUM)) {
        $data = $row[0] . "\t" . $row[1] . "\t" . $row[2] . "\n";
        print $data;
       }


With Mysqli:

$get->bind_result($id,$name,$loc);
 while ($get->fetch()) {
        print ($id, $name, $code);
    }


im using mysqli not PDO

@KonzMama, I edited my answer, i think you forgot to bind result variables in Mysqli
