I’m using a destructor to close the db connection.
function __destruct(){
var_dump($this->dblink);
mysql_close($this->dblink);
}
var dump gives me
resource(7) of type (mysql link) NULL
and the mysql_close() gives me:
Warning: mysql_close() expects parameter 1 to be resource, null given
Any thoughts?
EDIT
Thanks to the replies I found the issue. destruct is being called by another parent class. Pretty obvious to me now.
THANKS
The object is automatically destructed when the script is finished. The resource is freed as well. If the resource is freed before the object is destructed, you cannot close it. So, only close it if you need the connection to be closed before the script terminates. It is no use closing it when the script is already finishing. All resources are closed and cleaned up automatically.