David Casillas
David Casillas

Reputation: 1911

Get error 'call member function on non-object' with a valid mysqli_result object

I have the following PHP code in a class extending mysqli.

    $queryString = 'SELECT ' . ID_UBICACION . ' FROM ' . TABLE_UBICACION_EVENTO . ' WHERE ' . ID_EVENTO . '=' . $id;        
    $queryResult = $this->query($queryString);
    var_dump($queryResult);      
    while ( $row = $queryResult->fetch_assoc() ) { //This is line 1090!!!!!! 
        $queryString = 'DELETE FROM ' . TABLE_UBICACION . ' WHERE ' . ID_UBICACION . '=' . $row[ID_UBICACION]; 
        $queryResult = $this->query($queryString);    
    }

The output shows:

object(mysqli_result)#36 (0) { } 
Fatal error: Call to a member function fetch_assoc() on a non-object in /var/www/vhosts/davidcasillas.es/subdomains/aem/httpdocs/BaseDatos.php on line 1090

If $queryResult is a valid mysqli_result object, why do I get the error?

Upvotes: 0

Views: 890

Answers (3)

Muhammad Zeeshan
Muhammad Zeeshan

Reputation: 8856

You are resetting $queryResult in your while loop.

Upvotes: 1

Stefan Wisnewski
Stefan Wisnewski

Reputation: 56

you overwrite $queryResult in the loop ;)

Upvotes: 2

lanzz
lanzz

Reputation: 43168

You are replacing the value of $queryResult within your loop body. DELETE queries do not return a valid result resource, they return only a boolean success flag.

Upvotes: 1

Related Questions