Unable to connect to MySQL with PHP PDO

I’m not sure since you’re not sharing the actual values, but it seems you keep a space between the dot and the infinityfree.com part of the domain, as also shown here:

Would it be possible to share your actual values, redacting only the password? You’ve already shared your username and dbname, so showing the SQL URL in the code exactly as it is shouldn’t be an issue.

Take a look at this article too if you haven’t already:

Specifically this part: