here is an example code, not tested but should work and you can see how this can be done.
select_user_db(id) search a player in the db. if exists store status and time-stamp from db to global vars, if not add the player to the db ( see line 98 )
update_user_db(id,status,timestamp) to update status and timestamp from a player in the db
delete_user_db(id) to delete a player from the db
if you need help feel free to ask