0

为什么此函数成功执行数据库查询,但仍然导致致命错误:调用非对象上的成员函数 free()

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;
}

编辑:
这是上面的 db_connect() 函数:

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;
    }
}
4

1 回答 1

3

选择查询返回资源,插入查询不返回。你只能释放资源

于 2012-06-30T09:22:14.793 回答