PDO and Different MySQL Port Number

PDO and Different MySQL Port Number

Just in case you want to use a different MySQL port number than 3306 with PDO, be aware that this is not as easy as you might think. 

In order to get a different port working on your localhost you have to provide an IP address, because MySQL uses the UNIX socket per default when your host is configured as “localhost”.

I just wasted one hour to figure this out. So I now use ‘127.0.0.1’ instead of ‘localhost’, and it works fine.