user1091949
user1091949

Reputation: 1933

Why am I getting fatal error from mysqli_result::free after the query succeeds?

Why does this function successfully execute the database query, yet still results in Fatal error: Call to a member function free() on a non-object ?

private function record_login()
{
    $user_id = $this->user_id;
    $time = time();
    $ip_address = $this->ip_address;

    $link = $this->db_connect();

    $query = "INSERT INTO login_log (user_id, login_time, ip_address)
                    VALUES ('$user_id', '$time', '$ip_address')";

    $result = $link->query($query);

    if (!$result) {
        $this->log_error(); // This function does NOT get called
    }

    $result->free();
    $link->close();     
    return true;
}

EDIT:
Here is the db_connect() function from above:

private function db_connect() 
{
    $link = new mysqli('localhost', 'my_user', 'my_password', 'my_db');
    if(mysqli_connect_errno()) { 
        die(mysqli_connect_error());
    }  
    else {
        return $link;
    }
}

Upvotes: 0

Views: 84

Answers (1)

Puggan Se
Puggan Se

Reputation: 5846

Select-querys returns resources, insert-querys dosn't. you can only free resources

Upvotes: 3

Related Questions