fixed mysql locking to maintain a session