5

Note that you can specify a port number with "port=####", but this port number will be ignored if the host is localhost. If you want to connect to a local port other than the default, use host=127.0.0.1 instead of localhost.

Quoted from this page,has anyone verified if it has been fixed?

3 Answers 3

24

That isn't a bug. That is how MySQL is designed. When the host is "localhost", MySQL Unix clients use a Unix socket, AKA Unix Domain Socket, rather than a TCP/IP socket for the connection, thus the TCP port doesn't matter.

Reference: "4.2.2. Connecting to the MySQL Server"

1
  • 1
    What about Windows?
    – Pacerier
    Feb 19, 2017 at 22:24
6

That's most likely not a bug in PDO, but a feature of some database client library. For example, if you use psql (the PostgreSQL client) to connect to localhost, it will use UNIX sockets, but if you use 127.0.0.1, it will use TCP sockets and for that it obviously needs also the port number.

1

In my humble opinion you should be checking the PDO/PHP bug related pages.

But i don't think it's a bug. If you are on localhost you don't have to specify a port.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.