PHP PDO Intermittent “Can’t connect to MySQL server”

Ran into this problem when converting a site to use PHP PDO, and have no idea why this works. If your connection string includes the local server’s IP address, server name, or the website domain name all of these can cause intermittent connection errors. For some reason changing it to simply “localhost” fixes the problem.