Store a hash in a cookie to identify the user's account to keep logged in after close browser
I think this is a bad approach on two fronts (the second one is more important):


Having to check a randomly generated 'hash' against the database, to see if it has been used before, is inefficient. First of all, this is not a hash, it's a random string. A hash is created from something sensible, to verify it later. Can I assume you already have an unique identifier for each user in your database? You could store that in the cookie, it tells you which user it is. User id's don't need to be a secret. However, you don't want someone to change it and see information from another to user. To prevent this, you could add a small random string to the cookie, and in your database, to verify that they are who they say they are. Such a string is called a 'token'. An user is only valid if the user id and the token in the cookie match with the id and token in the database. Your queries will now probably be quicker because you can use the user id to look up the token.
Staying 'logged in' after closing the browser is done by not erasing the session cookie when the browser closes. It's as simple as that. See: https://www.php.net/manual/en/function.session-set-cookie-params.php (see 'lifetime', it defaults to 0).