Implemented the closeConnection function

I made an if statement in my function that checks if a variable has been set or not, and if not, then it will return null, and there wont be a need to close the connection because of so. I f a variable isset, then it will close the connection because of my written code.