It could be that the SATA cable was partly dislodged, have you moved the PC or knocked it recently? Other than that no real ideas.
Sounds to me like power problems. Used to get that when my PC was connected to a dodgy wall socket. Would require a cold boot to solve, but once had to do what you did - changing ports back & forth. Thats when I investigated the power supply. This lead me to the wall socket & if it wasn't for my (Tagan) PSU they could have been irrecoverable damage. Replaced the wall socket & got a UPS & some surge protectors all seems fine now