user4491462
user4491462

Reputation:

Call to undefined method mysqli::fetch_assoc()

im trying to make a simple mysqli class for my self, but there is a error, that i cant resolve. Call to undefined method mysqli::fetch_assoc() on line 20.

public function __construct() {
    $this->db = new mysqli('localhost','username','password','web');
    if (mysqli_connect_error()) {
        die('Connect Error (' . mysqli_connect_errno() . ') '
                . mysqli_connect_error());
    }
}

public function query($query) {
    $result = $this->db->query($query);
    return $result;
}

public function fetch($query) {
    if (!empty($query)) {
        while ($row = $this->db->fetch_assoc()) {  *//there are line 20*
            $data[] = $row;
        }
        return $data;
    } else {
        return false;
    }
}

Upvotes: 3

Views: 18216

Answers (2)

Abdulla Nilam
Abdulla Nilam

Reputation: 38642

This

$this->db->fetch_assoc()

should be

$this->$query->fetch_assoc()

Upvotes: 1

tino.codes
tino.codes

Reputation: 1507

You have to fetch the $result, not the $query or $this->db. But we need the rest of the code to help you.

I think you have to use this line:

while ($row = $query->fetch_assoc()) {

Upvotes: 4

Related Questions